pandas · Lesson 11.2 · Pro
Vectorise instead of apply
Rewrite row-by-row code as whole-column code with np.where, np.select and pd.cut, and see why it's faster.
In this lesson
- Whole-column maths beats a loop
- np.where for two outcomes
- np.select for several outcomes
- pd.cut for number ranges
Go Pro to read this lesson
Pro unlocks every lesson and practice problem in SQL, Python, pandas and NumPy, with answers and step-by-step explanations.