1# if the row value in column 'is_blue' is 1
2# Change the row value to 'Yes'
3# otherwise change it to 'No'
4df['is_blue'] = df['is_blue'].apply(lambda x: 'Yes' if (x == 1) else 'No')
5
6
7# You can also use mapping to accomplish the same result
8# Warning: Mapping only works once on the same column creates NaN's otherwise
9df['is_blue'] = df['is_blue'].map({0: 'No', 1: 'Yes'})
1df.rename(columns={"A": "a", "B": "b", "C": "c"},
2errors="raise", inplace=True)
3
1df_new = df.rename(columns={'A': 'a'}, index={'ONE': 'one'})
2print(df_new)
3# a B C
4# one 11 12 13
5# TWO 21 22 23
6# THREE 31 32 33
7
8print(df)
9# A B C
10# ONE 11 12 13
11# TWO 21 22 23
12# THREE 31 32 33
13