Skip to main contentSkip to solution

Consider the following Dataframe 'df':

SubjectAmitAshuAtulArnab
Maths80858290
Science75707983
Hindi82848878
English80707981

To drop a columns having label 'Amit' and 'Atul', which of the following statement is valid?

Solution

✅ Correct Option: 4

The pandas method to remove labels is drop(). Columns lie along axis 1, so df.drop(['Amit','Atul'], axis = 1) removes the 'Amit' and 'Atul' columns. It returns a new DataFrame and leaves df unchanged unless inplace=True is used.


Option 2: drop() is the right method, but axis = 0 looks for 'Amit' and 'Atul' in the row labels, so it raises a KeyError.

Options 1 and 3: pandas has no delete() method for DataFrames.

axis = 0 means rows (index) 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