python - how to join multiple csv files without repetition? -
i have 3 csv files should have same date column that:
file1.csv file2.csv file3.csv date,price1 date,price2 date,price3 2017-03-03,1900 2017-03-03,1200 2017-03-03,1220 2017-03-04,2900 2017-03-04,2200 2017-03-04,2233 2017-03-04,1300 2017-03-04,1549 2017-03-04,1520
i want join them , using python:
file4.csv date,price1,price2,price3 2017-03-03,1900,1200,1220 2017-03-04,2900,2200,2233 2017-03-04,1300,1549,1520
one can combine 2 files @ time. repeat process other files well.
import pandas pd df1 = pd.read_csv('file1.csv') df2 = pd.read_csv('file2.csv') df3 = pd.read_csv('file3.csv') df12 = pd.merge(df1, df2, how='outer', on='date') df123 = pd.merge(df12, df3, how='outer', on='date') print(df123)
Comments
Post a Comment