0
0
Pandasdata~5 mins

Dropping columns and rows in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the pandas method drop() do?
The drop() method removes specified rows or columns from a DataFrame.
Click to reveal answer
beginner
How do you drop a column named 'Age' from a DataFrame df?
Use df.drop('Age', axis=1) to drop the 'Age' column.
Click to reveal answer
beginner
What does the parameter axis=0 mean in drop()?
axis=0 means you want to drop rows by their labels.
Click to reveal answer
beginner
How can you drop multiple rows with labels 2 and 4 from a DataFrame df?
Use df.drop([2, 4], axis=0) to drop rows with labels 2 and 4.
Click to reveal answer
intermediate
What happens if you use inplace=True in drop()?
The DataFrame is changed directly without creating a new copy.
Click to reveal answer
Which parameter in drop() specifies if you want to drop rows or columns?
Aaxis
Blabels
Cinplace
Dcolumns
What is the default value of axis in drop()?
A0
B2
CNone
D1
How do you drop a column named 'Salary' without changing the original DataFrame?
Adf.drop('Salary', axis=1, inplace=True)
Bdf.drop('Salary', axis=1)
Cdf.drop('Salary', axis=0)
Ddf.drop(columns='Salary', inplace=True)
Which of these drops rows with labels 3 and 5?
Adf.drop([3, 5], axis=1)
Bdf.drop(columns=[3, 5])
Cdf.drop([3, 5], axis=0)
Ddf.drop(rows=[3, 5])
What does inplace=True do in drop()?
ADrops rows only
BReturns a new DataFrame
CDrops columns only
DModifies the original DataFrame directly
Explain how to drop a column and a row from a pandas DataFrame. Include the parameters you use.
Think about how axis=0 and axis=1 relate to rows and columns.
You got /4 concepts.
    Describe the difference between dropping rows and dropping columns in pandas.
    Focus on the axis parameter and what labels mean.
    You got /4 concepts.