Merge two csv files with python

pandas provides the concat function to merge two or more csv files.
1. Row merge

f1 = pd.read_csv('file1.csv')
f2 = pd.read_csv('file2.csv')
file = [f1,f2]
train = pd.concat(file)
train.to_csv("file3" + ".csv", index=0, sep=',')



2. Column merging can be achieved by setting axis=1 in the concat function

f1 = pd.read_csv('file1.csv')
f2 = pd.read_csv('file2.csv')
file = [f1,f2]
train = pd.concat(file,axis=1)
train.to_csv("file3" + ".csv", index=0, sep=',')


 

Guess you like

Origin blog.csdn.net/weixin_64338372/article/details/130097902