Interview practice question
pandas loop taking hours
Data Engineering · Python · Beginner
A teammate's pandas script loops through each row with iterrows to calculate a value and takes 2 hours. How would you speed it up?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- iterrows is slow because it runs Python code per row.
- Replace with vectorized column operations.
- Use np.where or np.select for conditional logic.
- Use merge instead of lookups inside the loop.
- Measure before and after.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.