Advertisements
Advertisements
Question
What if in the rename function we pass a value for a row label that does not exist?
Code Writing
Advertisements
Solution
If we pass a row label that does not exist in the rename() function, then no change will occur and the DataFrame will remain the same. he rename() function only changes the labels that are already present in the DataFrame. It ignores the labels that do not exist.
import pandas as pd
df = pd.DataFrame({'Marks': [85, 90, 78]}, index=['a', 'b', 'c'])
df_new = df.rename(index={'b': 'Beta', 'z': 'Omega'})
print(df_new)
Output:
| Marks | |
| a | 85 |
| Beta | 90 |
| c | 78 |
shaalaa.com
Is there an error in this question or solution?
