----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#纵向表合并--行相加
#concat方法,纵向数据合并(表结构相同,首尾相连)
import pandas as pd
df1=pd.read_excel('数据合并concat.xlsx', sheet_name='Sheetl')
df2=pd.read_excel('数据合并concat.xlsx', sheet_name='Sheet2')
df3=pd.read_excel('数据合并concat.xlsx', sheet_name='Sheet3')
#合并
df=pd.concat([df1,df2,df3], keys=['表1','表2' ,'表3' ],ignore_index=True) # ignore_index=True 表示不显示索引
df
##横向表合并--列相加
#concat 横向连接方式
import pandas as pd
df1=pd.read_excel('数据合并concat.xlsx', sheet_name='Sheetl')
df2=pd.read_excel('数据合并concat.xlsx', sheet_name='Sheet4')
df=pd.concat([df1,df2],axis=1)
#交叉合并--两表的交集
#concat 交叉连接
import pandas as pd
df1=pd.read_excel('数据合并concat.xlsx', sheet_name='Sheetl')
df2=pd.read_excel('数据合并concat.xlsx', sheet_name='Sheet4')
df=pd.concat([df1,df2],axis=1,join='inner')
浙公网安备 33010602011771号