+3 votes
in Programming Languages by (60.0k points)
I want to add a suffix to all column names of a pandas dataframe. Is there any function for it?

1 Answer

+2 votes
by (77.2k points)
selected by
 
Best answer

You can use the add_suffix() function of Pandas DataFrame. This function adds a suffix to labels for Series and columns for DataFrame.

Here is an example:

>>> import pandas as pd

>>> df = pd.DataFrame({'A':[1,2,3],'B':[11,12,13]})

>>> df

   A   B

0  1  11

1  2  12

2  3  13

>>> df.add_suffix('_col')

   A_col  B_col

0      1     11

1      2     12

2      3     13


...