Pandas is a python package for creating and manipulating dataframe. Most codes may encounter errors on attributeerror. The error Attributeerror: ‘dataframe’ object has no attribute ‘concat’ is such of them. Therefore in this tutorial, you will learn how to solve the Attributeerror: ‘dataframe’ object has no attribute ‘concat’ error.]
Cause of Attributeerror: ‘dataframe’ object has no attribute ‘concat’ Error
The main reason you are getting this error as you are using the calling the concat function on the dataframes you want to concate. Let’s say I have two dataframes. df1 and df2 and want to concanate. If I will use the below lines of code to perform that then I will get the error ‘dataframe’ object has no attribute ‘concat’
import pandas as pd
# Create two DataFrame objects
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df2 = pd.DataFrame({'A': [7, 8, 9], 'B': [10, 11, 12]})
# Concatenate the two DataFrame objects
df1.concat(df2)
print(result)
Output
AttributeError: 'DataFrame' object has no attribute 'concat'
Solution of Attributeerror: ‘dataframe’ object has no attribute ‘concat’ Error
If you are encountering this error then you are able to resolve it easily. The error was coming as you were using the concat() function on the dataframe. But the concat() function was for pandas, not the dataframe. Instead of df.concat() you will use the pd.concat() function.
Now you will not encounter the error when you run the below lines of code.
import pandas as pd
# Create two DataFrame objects
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df2 = pd.DataFrame({'A': [7, 8, 9], 'B': [10, 11, 12]})
# Concatenate the two DataFrame objects
result = pd.concat([df1, df2])
print(result)
A B
0 1 4
1 2 5
2 3 6
0 7 10
1 8 11
2 9 12
Conclusion
AttributeError most occurs when you are trying to use a function that is not available in the module or package. If you are getting the Attributeerror: ‘dataframe’ object has no attribute ‘concat’ error then the above solution will resolve the issues.
Leave a Reply