AttributeError: 'DataFrame' object has no attribute 'append'
时间: 2023-06-21 16:19:30 浏览: 460
这个错误通常出现在 Pandas DataFrame 对象上,意味着该对象没有名为“append”的属性或方法。通常,DataFrame 对象不提供 append 方法,而是提供了 concat 方法,用于在两个或多个 DataFrame 之间连接行或列。
如果你想将一个 DataFrame 连接到另一个 DataFrame 的末尾,可以使用 concat 方法。例如:
```
import pandas as pd
# 创建两个 DataFrame
df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]})
# 使用 concat 方法连接两个 DataFrame
result = pd.concat([df1, df2])
print(result)
```
这将输出一个包含 4 行和 2 列的 DataFrame,其中第一部分是 df1,第二部分是 df2。
如果你需要将单个行或列添加到 DataFrame 中,可以使用 loc 或 iloc 来设置新行或列的值。例如:
```
import pandas as pd
# 创建一个空的 DataFrame
df = pd.DataFrame(columns=['A', 'B'])
# 添加一行
df.loc[0] = [1, 2]
# 添加一列
df['C'] = [3, 4]
print(df)
```
这将输出一个包含 1 行和 3 列的 DataFrame,其中第一列是 A,第二列是 B,第三列是 C。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)