Attributeerror: ‘dataframe’ object has no attribute append error occurs because append() attribute is removed in Pandas 2.0.0 version. We can we concat() attribute to achieve similar functionality. In this article we will fix this attributeerror step by step. We will start from replication of the error. We will also explore the other alternative to fix this issue. So lets start.
As the first step we will replicate this error. To go into the depth.
In this step, we will create two dummy dataframe and then perform the append() function.
The replacement for append() attribute is concat() attribute. Lets try to ingest this function in the above code. I will resolve the error.
import pandas as pd
df1 = pd.DataFrame({'col1': [3,4], 'col2': [5,6]})
df2 = pd.DataFrame({'col1': [8], 'col2': [11]})
final = pd.concat([df1, df2])
final.head()
Lets run this code with concat() function or attribute and see the output.
There are many other ways also to fix this error. Lets explore them one by one. But I will recommend to opt concat() in the place of below solution.
In this approach we want to use append() attribute then we need to first convert the second dataframe and then we will append().
import pandas as pd
df1 = pd.DataFrame({'col1': [3,4], 'col2': [5,6]})
df2 = pd.DataFrame({'col1': [8], 'col2':[11] })
## Data Frame to dict conversion
mydict=df2.to_dict('dict')
df = df.append(mydict, ignore_index=True)
df.head()
Here we will use the second dataframe as series.
df1 = pd.DataFrame({'col1': [3,4], 'col2': [5,6]})
ser = pd.Series({'col1': 11, 'col2': 19})
final_df= df1.append(ser, ignore_index=True)
final_df.head()
Please refer the release notes form Pandas 2.0.0 for better understanding of the same AttributeError.
Thanks
Data Science Learner Team