.itertuples() in pandas – Fast Row Iteration in Python 2026 with Efficient Code
When you truly need to iterate over rows in a pandas DataFrame, .itertuples() is by far the fastest and most efficient option. In 2026, it remains the recommended method for row-wise iteration when vectorization is not possible.
This March 15, 2026 guide shows how to use .itertuples() effectively and why it is significantly better than .iterrows().
TL;DR — Key Takeaways 2026
.itertuples()is much faster than.iterrows()- It returns namedtuples, allowing fast attribute access
- Use it when you need row-by-row logic that cannot be vectorized
- Always prefer vectorized operations over any iteration when possible
- Free-threading safe and highly performant in modern Python
1. Basic Usage
import pandas as pd
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Charlie'],
'score': [85, 92, 78],
'age': [25, 30, 35]
})
# ✅ Fast and efficient way
for row in df.itertuples():
print(f"Player: {row.name}, Score: {row.score}, Age: {row.age}")
2. Advanced Usage Patterns
# 1. With index
for row in df.itertuples(index=True):
print(row.Index, row.name, row.score)
# 2. Skipping index for speed
for row in df.itertuples(index=False):
if row.score > 85:
print(row.name, "is excellent")
# 3. Real-world calculation
total = 0
for row in df.itertuples():
total += row.score * row.age
print("Weighted total:", total)
3. Performance Comparison 2026
| Method | Relative Speed | Memory Usage | Recommendation |
|---|---|---|---|
| Vectorized operations | 100x (fastest) | Low | Best choice |
.itertuples() | 20–50x | Low | Best for row iteration |
.apply(axis=1) | 5–10x | Medium | Use sparingly |
.iterrows() | 1x (slowest) | High | Avoid |
4. Best Practices with .itertuples() in 2026
- Use
.itertuples()when you must iterate row by row - Use
index=Falsewhen you don’t need the index for extra speed - Prefer vectorized operations whenever possible
- Keep the loop body simple to maximize performance
- Consider
.apply()only for complex row-wise logic
Conclusion — .itertuples() in pandas (2026)
.itertuples() is the fastest and most memory-efficient way to iterate over rows in a pandas DataFrame. While vectorized operations are always preferred, when iteration is truly necessary, .itertuples() is the clear winner over .iterrows() and .apply().
Next steps:
- Replace any
.iterrows()usage with.itertuples()or vectorized alternatives - Related articles: Introduction to pandas DataFrame Iteration 2026 • Efficient Python Code 2026