添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Diagram

AttributeError: ‘DataFrame’ object has no attribute ‘concat’ error occurs when you are using the concat() method on a dataframe, and the dataframe object does not have a concat attribute.

To fix the AttributeError: ‘DataFrame’ object has no attribute ‘concat’ error, use the Pandas concat() method properly and don’t use the concat() method on DataFrame.

Reproduce the error

import pandas as pd
# Creating a simple dataframe
df1 = pd.DataFrame({
  'A': [1, 2, 3],
  'B': [4, 5, 6]
# Creating another dataframe to append to df1
df2 = pd.DataFrame({
  'A': [7, 8, 9],
  'B': [10, 11, 12]
# concatenating df1 and df2
df = df1.concat(df2)
print(df)

Output

AttributeError: 'DataFrame' object has no attribute 'concat'

How to Fix It?

Use the pandas.concat() method and pass the df1, df2 as argument to concat both dataframes.

import pandas as pd
# Creating a simple dataframe
df1 = pd.DataFrame({
 'A': [1, 2, 3],
 'B': [4, 5, 6]
# Creating another dataframe to append to df1
df2 = pd.DataFrame({
 'A': [7, 8, 9],
 'B': [10, 11, 12]
# concatenating df1 and df2
df = pd.concat([df1, df2])
print(df)

Output

   A   B
0  1   4
1  2   5
2  3   6
0  7   10
1  8   11
2  9   12

And we fixed the error by implementing the solution! That’s all.

Related posts

AttributeError: ‘DataFrame’ object has no attribute ‘append’

 AttributeError: ‘DataFrame’ object has no attribute ‘ix’

AttributeError: ‘DataFrame’ object has no attribute ‘split’

AttributeError: ‘DataFrame’ object has no attribute ‘dtype’

AttributeError: ‘DataFrameGroupBy’ object has no attribute ‘set_index’