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

后端 未结 4 1204
眼角桃花
眼角桃花 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 06:06

    You can use nested merge

    merge_on = ['id','place','name','qty','unit']
    df1.merge(df2, on = merge_on).merge(df3, on = merge_on)
    
    
    
        id  place   name    qty unit    A   B   C   D
    0   1   NY      Tom     2   10      a   b   c   d
    1   2   TK      Ron     3   15      a   b   c   d
    2   3   Lon     Don     5   90      a   b   c   d
    3   4   Hk      Sam     4   49      a   b   c   d
    

提交回复
热议问题