我有三个pandas数据框,如下所示:
import pandas as pd
df1=pd.dataFrame ({
'Bus':['AM','AM','WM','PC','CC'],\
'IC/Third':['IC','Third','Third','IC','Third'],\
'Line':['PRV','PRV1','PRV2','PRV3','PRV4'],\
'Amount':[100,100,100,100,100]\
})
df1=df1.groupby(['Bus','IC/Third','Line']).agg({'Amount':'sum'})
df1.reset_index()
df2=df1.groupby(['Bus','Line']).agg({'Amount':'sum'})
df2.reset_index()
df3=pd.merge(df1,df2,on=['Bus','Line'],how='left')
df3
我正在尝试加入数据帧df1和df2,但收到错误。有什么想法吗?