Pandas: control new column names when merging two dataframes?

前端 未结 3 1050
北恋
北恋 2021-02-05 05:35

I would like to merge two Pandas dataframes together and control the names of the new column values.

I originally created the dataframes from CSV files. The original CS

相关标签:
3条回答
  • 2021-02-05 05:50

    You can rename all the columns of ad by setting its columns as follows.

    ad.columns = ['org', 'name', 'presents_spend', 'trees_spend']
    
    0 讨论(0)
  • 2021-02-05 06:02

    The suffixes option in the merge function does this. The defaults are suffixes=('_x', '_y').

    In general, renaming columns can be done with the rename method.

    0 讨论(0)
  • 2021-02-05 06:15

    Another way is adding suffix to the columns of your dataframe before merging:

    ad.columns = 'ad_' + ad.columns.values
    
    0 讨论(0)
提交回复
热议问题