Python Pandas merge only certain columns

后端 未结 5 572
小蘑菇
小蘑菇 2020-12-12 12:33

Is it possible to only merge some columns? I have a DataFrame df1 with columns x, y, z, and df2 with columns x, a ,b, c, d, e, f, etc.

I want to merge the two DataFr

5条回答
  •  情话喂你
    2020-12-12 13:06

    You could merge the sub-DataFrame (with just those columns):

    df2[list('xab')]  # df2 but only with columns x, a, and b
    
    df1.merge(df2[list('xab')])
    

提交回复
热议问题