Python Pandas merge only certain columns

后端 未结 5 553
小蘑菇
小蘑菇 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:02

    You want to use TWO brackets, so if you are doing a VLOOKUP sort of action:

    df = pd.merge(df,df2[['Key_Column','Target_Column']],on='Key_Column', how='left')
    

    This will give you everything in the original df + add that one corresponding column in df2 that you want to join.

提交回复
热议问题