Recall & Review
beginner
What does the
replace() function do in pandas?It substitutes specified values in a DataFrame or Series with new values you provide.
Click to reveal answer
beginner
How do you replace all occurrences of the value 0 with 100 in a pandas DataFrame?
Use
df.replace(0, 100) to change all 0 values to 100.Click to reveal answer
intermediate
Can
replace() handle multiple values at once? How?Yes, by passing a dictionary like
{old_value: new_value, ...} to replace multiple values in one call.Click to reveal answer
intermediate
What happens if you use
replace() without assigning the result back to the DataFrame?The original DataFrame stays the same because
replace() returns a new DataFrame by default and does not modify in place unless inplace=True is set.Click to reveal answer
beginner
How can you replace values only in a specific column using
replace()?Apply
replace() on that column like df['column_name'].replace(old, new).Click to reveal answer
What is the correct way to replace all 'cat' values with 'dog' in a pandas Series named
pets?✗ Incorrect
The
replace() method is used to substitute values in pandas objects.Which argument makes
replace() change the DataFrame without needing assignment?✗ Incorrect
Setting
inplace=True modifies the DataFrame directly.How do you replace multiple values at once in pandas?
✗ Incorrect
A dictionary like
{old1: new1, old2: new2} lets you replace many values in one call.If you want to replace values only in one column, what should you do?
✗ Incorrect
Applying
replace() on a single column changes values only there.What does
df.replace(0, 100) do?✗ Incorrect
It substitutes every 0 with 100 in the DataFrame.
Explain how to use
replace() to change multiple values in a pandas DataFrame.Think about how you can map old values to new ones in one step.
You got /3 concepts.
Describe the difference between using
replace() with and without the inplace=True argument.Consider if the original data changes immediately or not.
You got /3 concepts.