Skip to main contentSkip to solution

Consider the following table:

PriyaRichaRohitSohamRiya
Maths8587847690
Science8676866692
Hindi9291836897
English9081907594

How to delete columns having the labels 'Rohit' and 'Soham' if the dataframe is represented using 'df' ?

Solution

✅ Correct Option: 4

The pandas method for removing labels is drop(). Columns are removed with axis = 1, so the intended call is df.drop(['Rohit', 'Soham'], axis = 1). Option 4 is the only one that uses drop with axis = 1.

The closing bracket after 'Soham' is missing in the printed option, which is a typo. The intended statement is the one above.


Option 2: axis = 0 looks for 'Rohit' and 'Soham' among the row labels, so it would raise a KeyError.

Options 1 and 3: del() and delete() are not DataFrame methods. Option 3 also has a bracket typo.

Remember that axis = 0 means rows and axis = 1 means columns.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question