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

  1. Whole-column maths beats a loop
  2. np.where for two outcomes
  3. np.select for several outcomes
  4. pd.cut for number ranges