Pandas join issue: columns overlap but no suffix specified

后端 未结 4 1388
慢半拍i
慢半拍i 2020-12-02 06:56

I have following 2 data frames:

df_a =

     mukey  DI  PI
0   100000  35  14
1  1000005  44  14
2  1000006  44  14
3  1000007  43  13
4  1000008  43  13

df         


        
4条回答
  •  执念已碎
    2020-12-02 07:25

    This error indicates that the two tables have the 1 or more column names that have the same column name. The error message translates to: "I can see the same column in both tables but you haven't told me to rename either before bringing one of them in"

    You either want to delete one of the columns before bringing it in from the other on using del df['column name'], or use lsuffix to re-write the original column, or rsuffix to rename the one that is being brought it.

    df_a.join(df_b, on='mukey', how='left', lsuffix='_left', rsuffix='_right')
    

提交回复
热议问题