df rename rows code example
Example 1: rename column name pandas dataframe
df.rename(columns={"old_col1": "new_col1", "old_col2": "new_col2"})
Example 2: 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 3: df reanme columns
df_org = df.copy()
df_org.rename(columns={'A': 'a'}, index={'ONE': 'one'}, inplace=True)
print(df_org)
Example 4: rename row pandas
>>> df.rename({1: 2, 2: 4}, axis='index')
A B
0 1 4
2 2 5
4 3 6