Iterating with .iterrows() in pandas – Why You Should Avoid It in 2026
df.iterrows() is one of the most commonly used — and most criticized — methods in pandas. While it looks convenient, it is notoriously slow and should be avoided in almost all cases in 2026.
This March 15, 2026 guide explains why .iterrows() is slow and shows the modern, efficient alternatives you should use instead.
TL;DR — Key Takeaways 2026
.iterrows()is very slow because it returns a Series for each row- It is one of the worst ways to iterate over a DataFrame
- Prefer vectorized operations,
.itertuples(), or.apply()(sparingly) - Vectorized code is typically 50–200x faster than
.iterrows() - Never use
.iterrows()in production code unless absolutely necessary
1. The Problem with .iterrows()
import pandas as pd
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Charlie'],
'score': [85, 92, 78]
})
# ❌ Very slow and not Pythonic
for index, row in df.iterrows():
df.loc[index, 'score_double'] = row['score'] * 2
2. Better Alternatives in 2026
# ✅ Option 1: Vectorized (Recommended)
df['score_double'] = df['score'] * 2
# ✅ Option 2: itertuples() - Much faster than iterrows
for row in df.itertuples():
# row is a namedtuple - very fast access
pass
# ✅ Option 3: When you really need row-wise logic
df['score_double'] = df.apply(lambda row: row['score'] * 2, axis=1)
3. Performance Comparison 2026
| Method | Relative Speed | Recommendation |
|---|---|---|
| Vectorized operations | 100x (fastest) | Best choice |
.itertuples() | 20–50x | Acceptable when needed |
.apply(axis=1) | 5–15x | Use sparingly |
.iterrows() | 1x (slowest) | Avoid in production |
4. Best Practices in 2026
- Never use
.iterrows()for performance-critical code - Default to vectorized operations whenever possible
- Use
.itertuples()when you must iterate row by row - Use
.apply()only when vectorization is not feasible - Profile first — then decide if iteration is truly needed
Conclusion — Iterating with .iterrows() in 2026
.iterrows() is one of the slowest ways to iterate over a pandas DataFrame. In 2026, the most efficient pandas code almost never uses .iterrows(). Instead, it relies on vectorized operations, boolean indexing, and occasionally .itertuples() when row-by-row processing is unavoidable.
Next steps:
- Search your codebase for
.iterrows()and replace it with vectorized alternatives - Related articles: Introduction to pandas DataFrame Iteration 2026 • Eliminate Loops with NumPy 2026 • Efficient Python Code 2026