change the name of a column pandas code example
Example 1: python: change column name
df = df.rename(columns = {'myvar':'myvar_new'})
Example 2: rename column pandas
df_new = df.rename(columns={'A': 'a'}, index={'ONE': 'one'})
print(df_new)
print(df)
Example 3: Renaming row value in pandas
df['is_blue'] = df['is_blue'].apply(lambda x: 'Yes' if (x == 1) else 'No')
df['is_blue'] = df['is_blue'].map({0: 'No', 1: 'Yes'})
Example 4: name columns pandas
>gapminder.columns = ['country','year','population',
'continent','life_exp','gdp_per_cap']
Example 5: change column names pandas
df.columns = ['A','B']