set column names pandas dataframe code example
Example 1: df change column names
df.rename(columns={"A": "a", "B": "b", "C": "c"},
errors="raise", inplace=True)
Example 2: give column names to a dataframe
>gapminder.columns = ['country','year','population',
'continent','life_exp','gdp_per_cap']
Example 3: rename column pandas
>>> df.rename(columns={"A": "a", "B": "b", "C": "c"}, errors="raise")
Traceback (most recent call last):
KeyError: ['C'] not found in axis