'DataFrame' object has no attribute 'append'
时间: 2023-09-16 22:13:04 浏览: 143
Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
5星 · 资源好评率100%
This error occurs when you try to append a DataFrame using the `.append()` method, but the object you are trying to append to is not a DataFrame or does not have the attribute `.append()`.
To fix this error, you can try the following:
- Make sure that the object you are trying to append to is a DataFrame.
- Use the `concat()` method instead of `.append()` to concatenate two DataFrames.
- Create a new DataFrame and append the rows or columns to it using `.append()`.
Here is an example of how to use `concat()` to concatenate two DataFrames:
```
import pandas as pd
df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]})
concatenated_df = pd.concat([df1, df2])
print(concatenated_df)
```
This will output:
```
A B
0 1 3
1 2 4
0 5 7
1 6 8
```
阅读全文