हिंदी

What if in the rename function we pass a value for a row label that does not exist?

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 2: Data Handling using Pandas - I - Intext Questions [पृष्ठ ४८]

APPEARS IN

एनसीईआरटी Informatics Practices [English] Class 12
अध्याय 2 Data Handling using Pandas - I
Intext Questions | Q 11. | पृष्ठ ४८
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×