AttributeError: ‘DataFrame’ object has no attribute ‘concat’ ( Solved )

AttributeError 'DataFrame' object has no attribute 'concat' ( Solved )

Dataframe is created by the pandas’ packages. Once you have converted any datasets into dataframe then you can easily manipulate those datasets. Suppose you have two dataframes and want to concatenate the two dataframes then you may encounter the error AttributeError: ‘DataFrame’ object has no attribute ‘concat’. In this post, you will learn to know how to solve this error.

Why the AttributeError: ‘DataFrame’ object has no attribute ‘concat’ Error comes.

The main or root cause for getting this error is that you are not using the pandas.concat() method properly. You must be applying the concat() method on the single dataframe.

You will get the ‘DataFrame’ object has no attribute ‘concat’ error when you will run the below lines of code.

import numpy as np
import pandas as pd
np.random.seed(0)
df1 = pd.DataFrame({'col1': list('pqrstuv'), 'col2': np.random.choice(10, 7)})
df2 = pd.DataFrame({'col1': list('abcdefg')})
df1.concat()

Output

AttributeError dataframe object has no attribute concat
AttributeError dataframe object has no attribute concat error

You can see when I apply concat() method on a single dataframe df1 then  I got the error. You will get the same error if you apply this method to df2 dataframe.

Solution of DataFrame’ object has no attribute ‘concat’ Error

If you are getting this type of error then the solution is very simple. You have to properly concatenate the two dataframes. You don’t have to use the concat() method on the entire dataframe.

To concatenate the two dataframe you have to pass the two dataframe as an argument of the pandas.concat() method.

You will not get the error when you will run the below lines of code.

import numpy as np
import pandas as pd
np.random.seed(0)
df1 = pd.DataFrame({'col1': list('pqrstuv'), 'col2': np.random.choice(10, 7)})
df2 = pd.DataFrame({'col1': list('abcdefg')})
pd.concat([df1,df2],axis=1)

Output

concanating two dataframes
concanating two dataframes

Conclusion

The pandas package provides concat() method to join two dataframes. If you use this function simply on the dataframe then you will get the concat error. The above solution will solve the DataFrame’ object has no attribute ‘concat’ Error.

I hope you have liked this tutorial. If you are still getting this error and wants to get more information then contact us.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner