Pandas: control new column names when merging two dataframes?

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

ad.columns = 'ad_' + ad.columns.values

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.


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

ad.columns = ['org', 'name', 'presents_spend', 'trees_spend']

Tags:

Python

Pandas