Error database

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.

The message you saw
AttributeError: 'DataFrame' object has no attribute 'append'

By Updated

The error

Output
AttributeError: 'DataFrame' object has no attribute 'append'. Did you mean: '_append'?

Siblings from the same cleanup:

Output
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.

python
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.

python
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.

python
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 code

4. Pin pandas below 2.0 only as a stopgap for code you cannot edit.

bash
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.

The lessons behind this error.

  • Python for AI

    Pandas

    Pandas is a table with named columns that you can filter, group and summarise in one line. It is where almost every AI project starts, because real data arrives as a table.

Back to all errors