SpinTheMic
Pro

Interview practice question

Notebook is slow because of loops

Data Analyst · Python and Pandas · Beginner

Your notebook loops over 2 million rows with a for loop to calculate a discount column, and it takes ages. How do you speed it up?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Replace loop with vectorised ops.
  • np.where/np.select for conditions.
  • Avoid iterrows.
  • Merge or map for lookups.
  • Test equivalence.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics