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
What iterrows Really Returns
iterrows yields an index and a Series for each row. Building that Series costs time, and because a Series has a single dtype, mixed rows are upcast: integers can become floats when the row also contains a float.
That type change can cause subtle bugs, such as an id column turning into 101.0. itertuples keeps each column's type and is much faster, so it is the better choice for row loops.
Changes made to the row Series do not write back to the DataFrame, which surprises many beginners.
Worked Example: Type Changes and Missing Writes
We show the dtype change and the lost update.
import pandas as pd
df = pd.DataFrame({"order_id": [101, 102], "amount": [19.99, 5.0]})
for _, row in df.iterrows():
print(type(row["order_id"]).__name__, row["order_id"])
for row in df.itertuples():
print(type(row.order_id).__name__, row.order_id)
for _, row in df.iterrows():
row["amount"] = 0
print(df["amount"].tolist())
With iterrows, order ids come back as floats such as 101.0, while itertuples keeps them as integers. Setting row["amount"] inside the loop leaves the DataFrame unchanged, so the amounts are still 19.99 and 5.0.
Practical Tips
If you still need iterrows for a quick exploration, use it on a small sample, such as df.head(), and switch to a better method before the code runs on full data.
Writing results back should happen after the loop: collect values in a list and assign the list as a new column. For conditional updates, df.loc with a boolean mask changes all matching rows in one vectorised step, which is both faster and safer than modifying rows one at a time.
In short, treat iterrows as a debugging aid rather than a production tool.
Replacing it with vectorised code or itertuples is usually a small change with a large payoff, and the resulting code is often shorter as well.
Common Mistakes
- Expecting iterrows to preserve dtypes.
- Trying to modify the DataFrame through the row.
- Using iterrows on large tables.
- Ignoring vectorised alternatives.
Quick Summary
- iterrows builds a Series per row.
- Mixed rows are upcast.
- Row changes do not write back.
- Prefer itertuples or vectorised code.
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