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

Difference Between concat() and append() –

Most developers get confused in concat() and append() with dataframe. See there is a clear difference that concat() operations work on column and row. I mean we can combine two or more dataframes in both axes but the append() function will work in rows only. One more major difference is that concat() can involve more than two dataframes at a time but append() can only involve two dataframe at a time.

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 want to get more information then contact us. Please refer to the below articles for more clarity on the topic.

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

AttributeError: dataframe’ object has no attribute ‘dtype’ ( Solved )

Thanks

Data Science Learner Team

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.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner