Question:

In a Pandas DataFrame, which value for axis will be used to delete a column?

Show Hint

In Pandas, axis 0 means rows and axis 1 means columns, so use the axis that points to columns.
Updated On: Oct 20, 2026
  • axis = -1
  • axis = 0
  • axis = 1
  • axis = 2
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Recall how axis works in a DataFrame:
A DataFrame has two axes. axis = 0 stands for rows (the index). axis = 1 stands for columns.
Methods such as drop() use axis to decide whether a row label or a column label is removed.

Step 2: Apply this to deleting a column:
To delete a column we write df.drop('colname', axis=1). Here Pandas looks for 'colname' among the column labels and removes it.
With axis=0 it would look in the row index instead.

Step 3: Check option (A) axis = -1:
Pandas accepts only 0 and 1 (or the names 'index' and 'columns') for a DataFrame. Running df.drop('a', axis=-1) gives ValueError: No axis named -1. So (A) is wrong.

Step 4: Check option (B) axis = 0:
This removes rows, not columns. So (B) is wrong.

Step 5: Check option (D) axis = 2:
A DataFrame has only two axes (0 and 1). axis = 2 raises an error. So (D) is wrong.

Final Answer:
A column is deleted with axis = 1. This is option (C).
Was this answer helpful?
0
0