Vectorized Operations: Speed Secrets
It's **Day 122**, and we're talking about **Vectorization**. This is the single biggest difference between a "Python Programmer" and a "Data Scientist."
The Bad Way (Loops)
# DO NOT DO THIS
for row in df.iterrows():
df['total'] = row['price'] * 1.15
The Good Way (Vectorized)
# DO THIS
df['total'] = df['price'] * 1.15
Why is it different?
When you write a loop, Python has to check the data type, find the memory, and run the math for every single row.
When you use the vectorized version, Pandas hands the entire column to a **C engine** (NumPy). It performs the math on every row simultaneously at the hardware level.
The Senior Rule
If شما find yourself writing `for x in df`, stop. Ask yourself: "How can I do this with a vectorized Pandas function?"
Your Task for Today
Measure the time it takes to multiply a 1,000,000 row column using a Loop vs the Vectorized method. (Hint: use `time.time()`).
*Day 123: Handling Duplicates (The Pythonic Way).*