AttributeError: 'DataFrame' object has no attribute 'append'
pandas 2.0 removed DataFrame.append. Use pd.concat — or better, collect rows in a list and build the frame once at the end.
Updated
The error
AttributeError: 'DataFrame' object has no attribute 'append'. Did you mean: '_append'?
Siblings from the same cleanup:
AttributeError: 'DataFrame' object has no attribute 'iteritems' AttributeError: 'DataFrame' object has no attribute 'ix'
What it means
Your code calls a method that pandas removed. DataFrame.append was deprecated in pandas 1.4 and deleted in pandas 2.0 (April 2023). The code is not wrong for the pandas it was written against — it is running against a newer pandas. Old tutorials and old Stack Overflow answers keep this error alive.
Do not take the _append suggestion. Underscore methods are private internals and can vanish without notice.
Why it happens
append was removed for a good reason worth knowing: each call copied the entire frame. Appending in a loop copied the data again on every iteration, which made loops brutally slow on real datasets. The replacements avoid that trap.
How to fix it
1. For a one-off combination, use pd.concat.
df = pd.concat([df, new_rows], ignore_index=True)ignore_index=True renumbers rows, which is what append did by default.
2. For building a frame in a loop, collect dicts and construct once. This is the fast pattern.
rows = []
for record in source:
rows.append({"name": record.name, "score": record.score})
df = pd.DataFrame(rows)One construction at the end, no repeated copying.
3. Translate the other removed names.
for name, col in df.items(): # was: df.iteritems()
...
df.loc[3, "price"] # was: df.ix[3, "price"]
df.to_numpy() # was: df.as_matrix() / df.values in old code4. Pin pandas below 2.0 only as a stopgap for code you cannot edit.
pip install "pandas<2.0"Treat this as temporary. Old pandas will fall behind NumPy and Python versions quickly.
How to prevent it
When copying code from a tutorial, check its date against your installed version (pd.__version__). Run your code once with warnings visible — pandas deprecates loudly, usually for several releases, before it removes. Fix FutureWarning messages when they appear and version bumps stop hurting.
Related errors
- module 'numpy' has no attribute 'float' — the NumPy edition of the same story
- A module compiled using NumPy 1.x cannot be run in NumPy 2
- SettingWithCopyWarning