Question:

 Which of the following are the correct commands to delete a column from the DataFrame df1

Show Hint

Remember: For dropping a column in Pandas, use \texttt{axis=1} or \texttt{axis='columns'}. If you want permanent changes, use \texttt{inplace=True}, otherwise assign the result back to the DataFrame.
Updated On: Sep 18, 2025
  • df1 = df1.drop(column_name, axis=1)
  • df1.drop(column_name, axis=columns, inplace=True)
  • df1.drop(column_name, axis='columns', inplace=True)
  • df1.drop(column_name, axis=1, inplace=True)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Recall how to delete a column in Pandas. 
The drop() method is used to remove rows or columns from a DataFrame.

  • To delete a column, we set axis=1 (or equivalently, axis='columns').
  • The parameter inplace=True modifies the DataFrame directly; otherwise, a new DataFrame is returned.


Step 2: Check each option.
- Option (A): df1 = df1.drop(column__name, axis=1) → Correct. It drops the column and reassigns the DataFrame. 
- Option (B): df1.drop(column__name, axis=columns, inplace=True) → Incorrect. axis=columns is not valid syntax (should be string 'columns'). 
- Option (C): df1.drop(column__name, axis='columns', inplace=True) → Correct. This is equivalent to axis=1
- Option (D): df1.drop(column__name, axis=1, inplace=True) → Correct. Drops the column directly with inplace modification. 

Step 3: Conclusion.
The correct commands are (A), (C), and (D). 
Final Answer: \[ \boxed{\text{Option (1): (A), (C), and (D) only}} \]

Was this answer helpful?
0
0

Questions Asked in CUET exam

View More Questions