Now that a newer version of Pandas has been released, some of the previously deprecated functionality in older versions will no longer work. pandas.DataFrame.append()
method has been deprecated since Pandas version 1.4.0, and the same applies for the Series API, pandas.Series.append()
.
Solving AttributeError: ‘DataFrame’ Object Has No Attribute ‘Append’
AttributeError: ‘DataFrame’ object has no attribute ‘append’
occurs in Pandas versions 2.0 and beyond when the append()
method is used to link two DataFrames together. Since the append()
method was removed in the 2.0 update, the error can be resolved by replacing append()
with concat()
.
As of Pandas version 2.0.0, the append()
method has been completely removed, see issue 35407. Therefore, code referencing this method will now report the following error:
AttributeError: 'DataFrame' object has no attribute 'append'
In this short tutorial, we will demonstrate how a Pandas DataFrame can be concatenated with other DataFrame, or even other Python objects, such as dictionaries, using the new, recommended syntax.
How to Solve AttributeError: ‘DataFrame’ Object Has No Attribute ‘Append’
In older Pandas versions, the concatenation of DataFrames could have been achieved with the use of append()
method. The example code snippet below demonstrates how Pandas versions older than version 2.0 could be used to do so:
# Old syntax
import pandas as pd
# DataFrames
df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
df1.append(df2)
# Series
pd.Series([1, 2]).append(pd.Series([3, 4])
As of Pandas 2.0, in order to concatenate multiple DataFrames or series together, you should instead call the concat()
method, as illustrated below:
# New syntax, compatible with pandas v2.0
import pandas as pd
# DataFrames
df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
pd.concat([df1, df2])
# Series
pd.concat([pd.Series([1, 2]), pd.Series([3, 4])])
How to Determine Which Pandas Version You Are Running
If you are unsure about what Pandas version you are running, there are a few different ways to find out. You can programmatically do so by calling the following snippet:
import pandas as pd
print(pd.__version__)
Alternatively, you can find out directly from pip by running the following command, while making sure you are in the desired virtual environment:
$ pip list | grep pandas
Avoiding AttributeError: ‘DataFrame’ Object Has No Attribute ‘Append’
In this short tutorial, we discussed how you can potentially concatenate Pandas DataFrames using the new, recommended syntax following the new major release of Pandas 2.0.
Now that the append()
method (deprecated as of v1.4.0) has been completely removed as of Pandas 2.0, the new concat()
method should be used instead. The same applies for the Pandas Series API that no longer has the append member.
Frequently Asked Questions
What causes the AttributeError: ‘DataFrame’ object has no attribute ‘append’?
AttributeError: ‘DataFrame’ object has no attribute ‘append’
occurs when a user attempts to use the append()
method to concatenate multiple DataFrames together, which has been completely removed in Pandas version 2.0.0.
How do you fix the AttributeError: ‘DataFrame’ object has no attribute ‘append’?
AttributeError: ‘DataFrame’ object has no attribute ‘append’
can be solved by replacing append()
with the concat()
method to merge two or more Pandas DataFrames together.