pandas join DataFrame force suffix?

后端 未结 4 1572
暖寄归人
暖寄归人 2021-02-05 02:32

How can I force a suffix on a merge or join. I understand it\'s possible to provide one if there is a collision but in my case I\'m merging df1 with df2 which doesn\'t cause an

4条回答
  •  死守一世寂寞
    2021-02-05 03:09

    As of pandas version 0.24.2 you can add a suffix to column names on a DataFrame using the add_suffix method.

    This makes a one-liner merge command with force-suffix more bearable, for example:

    
    df_merged = df1.merge(df2.add_suffix('_2'))
    
    

提交回复
热议问题