Advertisements
Advertisements
प्रश्न
What would happen if the label or row index passed is not present in the DataFrame?
कोड लेखन
Advertisements
उत्तर
If the label or row index passed is not present in the DataFrame, then an error will occur if we try to access or modify it. The DataFrame can only perform operations on existing labels or indexes. If the label does not exist, Pandas cannot find it.
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
