python pandas rename multiple column headers the same way
df.add_suffix('X') HeaderAX HeaderBX HeaderCX0 476 4365 457
And the sister methodpd.DataFrame.add_prefix
df.add_prefix('X') XHeaderA XHeaderB XHeaderC0 476 4365 457
You can also use the pd.DataFrame.rename
method and pass a function. To accomplish the same thing:
df.rename(columns='{}X'.format) HeaderAX HeaderBX HeaderCX0 476 4365 457
In this example, '{}X'.format
is a function that takes a single argument and appends an 'X'
The advantage of this method is that you can use inplace=True
if you chose to.