how to change the column names in pandas code example

Example 1: rename column name pandas dataframe

df.rename(columns={"old_col1": "new_col1", "old_col2": "new_col2"})

Example 2: python: change column name

df = df.rename(columns = {'myvar':'myvar_new'})

Example 3: df change column names

df.rename(columns={"A": "a", "B": "b", "C": "c"},
errors="raise", inplace=True)

Example 4: how to change column name in pandas

print(df.rename(columns={'A': 'a', 'C': 'c'}))
#         a   B   c
# ONE    11  12  13
# TWO    21  22  23
# THREE  31  32  33

Example 5: how to give name to column in pandas

>gapminder.rename(columns={'pop':'population',
                          'lifeExp':'life_exp',
                          'gdpPercap':'gdp_per_cap'}, 
                 inplace=True)
 
>print(gapminder.columns)
 
Index([u'country', u'year', u'population', u'continent', u'life_exp',
       u'gdp_per_cap'],
      dtype='object')
 
>gapminder.head(3)
 
       country  year  population continent  life_exp  gdp_per_cap
0  Afghanistan  1952     8425333      Asia    28.801   779.445314
1  Afghanistan  1957     9240934      Asia    30.332   820.853030
2  Afghanistan  1962    10267083      Asia    31.997   853.100710

Example 6: dataframe change column names

#Pandas for Python

df.coloumns = ['A','B']