import pandas as pd
#sample DataFrame 1
sampleDF1 = pd.DataFrame({'columnA': list('abcdef'), 'columnB': range(6)})
#sample DataFrame 2
sampleDF2 = pd.DataFrame({'columnA': list('ghijkl')})
#sample DataFrame 3
sampleDF3 = pd.DataFrame({'columnB': range(6, 12)})
# the following will return a DataFrame’ object has no attribute ‘concat’ Error
sampleDF1.concat()
The script above will result like the following:
Solution: "AttributeError: 'DataFrame' object has no attribute 'concat'" [Solved]
In the first Python script I provided resulted in an attribute error and this error can be easily fixed by following the right way of using the
Pandas
concat()
method. We must call the said method from the module itself then list the created
DataFrames
as the attribute of the method and set the method options that we want to.
Here's the correct way of using the
Pandas
contact()
method:
import pandas as pd
#sample DataFrame 1
sampleDF1 = pd.DataFrame({'columnA': list('abcdef'), 'columnB': range(6)})
#sample DataFrame 2
sampleDF2 = pd.DataFrame({'columnA': list('ghijkl')})
#sample DataFrame 3
sampleDF3 = pd.DataFrame({'columnB': range(6, 12)})
# correct way to use concat method of pandas
print(pd.concat([sampleDF1, sampleDF2, sampleDF3], axis=1))
And this will execute the script something like the following:
As you can see, the
DataFrames
were listed on the
concat()
method and not calling the said method from the created
DataFrames
.
There you go! That is how you can fix or solve the
AttributeError: 'DataFrame' object has no attribute 'concat'
in
Python
. We must understand first where the method or object should be called to avoid or prevent this kind of attribute error in
Python
to occur.
That's it! I hope this
Solving"AttributeError: 'DataFrame' object has no attribute 'concat'" Error in Python
article will help you with what you are looking for and will be useful for your current or future
Python Projects
.
Explore more on this website for more
Tutorials
and
Free Source Codes.
Happy Coding =)