AttributeError: 'Series' object has no attribute 'iteritems' (Python) — how to fix
AttributeError: 'Series' object has no attribute 'iteritems'
AttributeError: 'DataFrame' object has no attribute 'iteritems'
Quick fix: Replace .iteritems() with .items(). If the call is inside a library (for example an older PySpark calling it during createDataFrame), upgrade that library, or pin pip install "pandas<2" until you can.
What it means
iteritems() was deprecated in pandas 1.5 and removed in pandas 2.0, on both Series and DataFrame. Code written for older pandas (or a library that still calls it) now fails with this AttributeError.
Check your version:
python -c "import pandas; print(pandas.__version__)"
Fix 1: use .items() in your code
.items() is a drop-in replacement and has existed for many years, so it also works on old pandas.
# Series: yields (index, value)
for idx, value in s.items():
print(idx, value)
# DataFrame: yields (column name, column Series)
for col, series in df.items():
print(col, series.dtype)
Search the project for leftovers:
grep -rn "iteritems" --include=*.py .
Note: plain Python dicts have the same story — dict.iteritems() was Python 2 only; see dict object has no attribute iteritems.
Fix 2: a library calls iteritems (PySpark and others)
If the traceback ends inside site-packages, the call isn't yours. A well-known case is older PySpark converting a pandas DataFrame:
spark.createDataFrame(pdf)
# AttributeError: 'DataFrame' object has no attribute 'iteritems'
Upgrade the library to a release that supports pandas 2:
pip install -U pyspark
If the library can't be upgraded (fixed cluster runtime, for example), pin pandas below 2:
pip install "pandas<2"
Fix 3: temporary shim
As a last resort, while waiting for a library fix, you can restore the alias at startup before the library is used:
import pandas as pd
if not hasattr(pd.DataFrame, "iteritems"):
pd.DataFrame.iteritems = pd.DataFrame.items
if not hasattr(pd.Series, "iteritems"):
pd.Series.iteritems = pd.Series.items
This is a monkey-patch; remove it once the dependency is upgraded.
Often you don't need to loop at all
Iterating row by row or column by column is slow in pandas. Many loops can be replaced with vectorised operations:
# instead of looping over items to build a new Series
s2 = s * 2
df_types = df.dtypes # instead of looping to read each column's dtype
Other pandas 2.0 removals you may hit next
DataFrame.append→pd.concat([df, other])Series.iteritems/DataFrame.iteritems→.items()
If several of these appear at once, the code was written for pandas 1.x; pinning pandas<2 buys time while you migrate.
Last updated 2026-12-05.