I would like to combine multiple csv files into one csv file. The csv file are all in same format: date are all with in the same period, Adj Close is the column that I wanna combine
For example:
Excel file 1:
Date Adj Close
1/12/2014 100
.....
31/12/2019 101
Excel file 2:
Date Adj Close
1/12/2014 200
.....
31/12/2019 201
I want the output be like something like this:
Date Adj Close Adj Close
1/12/2014 100 200
.....
31/12/2019 101 201
I have browse stackoverflow posts and some youtube videos and found the code below:
import os
import glob
import pandas as pd
def concatenate(indir = "C:\\Users\\Nathan\\Desktop\\Stock Data",
outfile = "C:\\Users\\Nathan\\Desktop\\Stock Data\\combinestockdata.csv"):
os.chdir(indir)
filelist = glob.glob("*.csv")
dflist = []
for filename in filelist:
print(filename)
df = pd.read_csv(filename,header= None)
dflist.append(df)
concatDf = pd.concat(dflist,axis = 0)
concatDf.to_csv(outfile,index=None)
However, below is what i get in the combine file:
Date Adj close 1/12/2014 100 ... 31/12/2019 101 1/12/2014 200 ... 31/12/2019 201
Instead of merging the list it simply adding file2 to file1, what should I do?