DataFrame.append() is RemovedThe df.append() method was deprecated and permanently removed in Pandas 2.0. If you run legacy code using append(), Python will raise an AttributeError.
All row-adding and concatenation tasks should now use the high-performance pd.concat() function:
Previously, developers used to append rows or dictionaries directly to a DataFrame using the instance method:
# LEGACY CODE (DO NOT USE IN PANDAS 2.0+)
import pandas as pd
df = pd.DataFrame({'Name': ['Ravi'], 'Marks': [85]})
new_row = {'Name': 'Raju', 'Marks': 90}
# This will throw an AttributeError in modern Pandas
# df = df.append(new_row, ignore_index=True)
Error Raised:
AttributeError: 'DataFrame' object has no attribute 'append'
pd.concat()To achieve the exact same result in modern Pandas, wrap your dictionary into a single-row DataFrame and pass it to pd.concat():
# MODERN PANDAS 2.0+ EQUIVALENT
import pandas as pd
df = pd.DataFrame({'Name': ['Ravi'], 'Marks': [85]})
new_row_df = pd.DataFrame([{'Name': 'Raju', 'Marks': 90}])
# Use pd.concat instead
df = pd.concat([df, new_row_df], ignore_index=True)
print(df)
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.