Advertisements
Advertisements
प्रश्न
What if in the rename function we pass a value for a row label that does not exist?
कोड लेखन
Advertisements
उत्तर
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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
