Concatenate distinct columns in two dataframes using pandas (and append similar columns)

后端 未结 4 1190
眼角桃花
眼角桃花 2020-12-17 05:29

My question is closely related to Pandas Merge - How to avoid duplicating columns but not identical.

I want to concatenate the columns that are diff

4条回答
  •  一向
    一向 (楼主)
    2020-12-17 05:49

    Using concat with groupby and first:

    pd.concat([df1, df2, df3], 1).groupby(level=0, axis=1).first()
    

       A  B  C  D  id name place  qty  unit
    0  a  b  c  d   1  Tom    NY    2    10
    1  a  b  c  d   2  Ron    TK    3    15
    2  a  b  c  d   3  Don   Lon    5    90
    3  a  b  c  d   4  Sam    Hk    4    49
    

提交回复
热议问题