English

What would happen if the label or row index passed is not present in the DataFrame?

Advertisements
Advertisements

Question

What would happen if the label or row index passed is not present in the DataFrame?

Code Writing
Advertisements

Solution

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
  Is there an error in this question or solution?
Chapter 4: Plotting Data using Matplotlib - Intext Questions [Page 127]

APPEARS IN

NCERT Informatics Practices [English] Class 12
Chapter 4 Plotting Data using Matplotlib
Intext Questions | Q 6. | Page 127
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×