Pandas: join DataFrames on field with different names?

前端 未结 2 1076
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 04:19

According to this documentation I can only make a join between fields having the same name.

Do you know if it\'s possible to join two DataFrames on a field having di

2条回答
  •  盖世英雄少女心
    2020-12-05 04:52

    I think what you want is possible using merge. Pass in the keyword arguments for left_on and right_on to tell Pandas which column(s) from each DataFrame to use as keys:

    pandas.merge(df1, df2, how='left', left_on=['id_key'], right_on=['fk_key'])
    

    The documentation describes this in more detail on this page.

提交回复
热议问题