Consider the following Dataframe 'df':
Subject Amit Ashu Atul Arnab Maths 80 85 82 90 Science 75 70 79 83 Hindi 82 84 88 78 English 80 70 79 81
To drop a columns having label 'Amit' and 'Atul', which of the following statement is valid?
Consider the following Dataframe 'df':
| Subject | Amit | Ashu | Atul | Arnab |
|---|---|---|---|---|
| Maths | 80 | 85 | 82 | 90 |
| Science | 75 | 70 | 79 | 83 |
| Hindi | 82 | 84 | 88 | 78 |
| English | 80 | 70 | 79 | 81 |
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.
Related questions:
2025: 30 May Shift 2
2025: 21 May Shift 1
2026: 31 May Shift 1