append、merge、join、concat、 合并多个文件或者电子表格中的数据 import pandas as pd d=pd.read_excel('data.xlsx') d2=pd.read_excel('data2.xlsx') d4=pd.read_excel('data4.xlsx') #d3=d2.append(d4) #merge合并多个 d5=pd.merge(d2,d4,on='sno') d6=pd.DataFrame({'key1':['A','B','C'],'value1':['1','2','3']}) d7=pd.DataFrame({'key1':['B','C','D'],'value1':['1','2','3']}) d8=pd.merge(d6,d7,on='key1',how='left')#相当于excel中vlookup函数 print(d8) d8=pd.DataFrame({'key1':['A','B','C']},index=['1','2','3']) d9=pd.DataFrame({'key2':['B','C','D']},index=['3','4','5']) #d10=d8.join(d9,how="inner")#两个表中相同的行 d11=pd.concat([d8,d9])#默认用index进行合并 print(d11)
pandas对多个数据进行合并
最新推荐文章于 2023-11-14 14:29:43 发布