Recall & Review
beginner
What is a vectorized operation in pandas?
A vectorized operation applies a function to an entire column or DataFrame at once, using optimized C code under the hood. It is fast and efficient because it avoids explicit loops.
Click to reveal answer
beginner
When should you use the apply() function in pandas?
Use apply() when you need to run a custom function that is not available as a built-in vectorized operation. It works row-wise or column-wise but is slower than vectorized methods.
Click to reveal answer
intermediate
Why are vectorized operations preferred over apply() in pandas?
Vectorized operations are faster and use less memory because they run optimized code internally. apply() is slower because it runs Python code repeatedly for each row or element.
Click to reveal answer
beginner
Give an example of a vectorized operation in pandas.
Adding 1 to every value in a column: df['col'] + 1 is vectorized and fast.
Click to reveal answer
intermediate
What is a downside of using apply() in pandas?
apply() can be slow on large datasets because it runs Python functions repeatedly, which is less efficient than built-in vectorized methods.
Click to reveal answer
Which method is generally faster for element-wise operations in pandas?
✗ Incorrect
Vectorized operations use optimized code and are faster than apply() or loops.
When should you choose apply() over vectorized operations?
✗ Incorrect
apply() is useful for custom functions that don't have vectorized equivalents.
What does a vectorized operation avoid that apply() uses?
✗ Incorrect
Vectorized operations avoid explicit Python loops, making them faster.
Which of these is an example of a vectorized operation?
✗ Incorrect
Adding 1 directly to the column uses vectorized addition.
What is a common drawback of using apply() on large datasets?
✗ Incorrect
apply() is slower because it calls Python functions repeatedly for each element or row.
Explain in your own words when to use apply() versus vectorized operations in pandas.
Think about speed and the type of function you need to run.
You got /4 concepts.
Describe the performance differences between apply() and vectorized operations with an example.
Consider how pandas handles operations internally.
You got /4 concepts.