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?✗ Incorrect
The
axis parameter tells pandas whether to drop rows (axis=0) or columns (axis=1).What is the default value of
axis in drop()?✗ Incorrect
By default,
axis=0, so drop() removes rows unless specified otherwise.How do you drop a column named 'Salary' without changing the original DataFrame?
✗ Incorrect
Using
df.drop('Salary', axis=1) returns a new DataFrame without the 'Salary' column, leaving the original unchanged.Which of these drops rows with labels 3 and 5?
✗ Incorrect
To drop rows by label, use
axis=0 with the list of labels.What does
inplace=True do in drop()?✗ Incorrect
inplace=True changes the original DataFrame without making a copy.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.