had = had.append(temp,ignore_index=True)AttributeError: 'DataFrame' object has no attribute 'append'
时间: 2024-05-20 13:09:05 浏览: 15
这个错误提示是因为 pandas 的 DataFrame 类没有名为 append 的方法,所以不能直接调用。如果您想将 temp 添加到 had 这个 DataFrame 中,可以使用 concat 方法。具体来说,可以使用以下代码:
```python
had = pd.concat([had, temp], ignore_index=True)
```
这样,temp 中的数据就会被添加到 had 的最后一行,并且重新生成一个 DataFrame。同时,由于 ignore_index=True 的设置,新生成的 DataFrame 会重新编号。
相关问题
list.append出错AttributeError: 'DataFrame' object has no attribute 'append'
在Pandas中,DataFrame对象没有append()方法。如果您想将行添加到DataFrame中,可以使用concat()方法或append()方法。下面是两种解决方案:
1.使用concat()方法将行添加到DataFrame中:
```python
import pandas as pd
# 创建一个空的DataFrame
df = pd.DataFrame(columns=['A', 'B'])
# 创建要添加的行
new_row = pd.DataFrame({'A': [1], 'B': [2]})
# 使用concat()方法将新行添加到DataFrame中
df = pd.concat([df, new_row], ignore_index=True)
# 打印DataFrame
print(df)
```
2.使用append()方法将行添加到DataFrame中:
```python
import pandas as pd
# 创建一个空的DataFrame
df = pd.DataFrame(columns=['A', 'B'])
# 创建要添加的行
new_row = pd.DataFrame({'A': [1], 'B': [2]})
# 使用append()方法将新行添加到DataFrame中
df = df.append(new_row, ignore_index=True)
# 打印DataFrame
print(df)
```
'DataFrame' object has no attribute 'append' File "D:\chapter12\demo\code\123.py", line 24, in <module> hit_count_7 = hit_count_7.append([{'用户数': time}], ignore_index=True) AttributeError: 'DataFrame' object has no attribute 'append'
Based on the error message you provided, it seems that you are trying to use the `append()` method on a DataFrame object, but this method does not exist for DataFrames. Instead, you can use the `concat()` method to concatenate DataFrames vertically.
Here's an example of how you can use `concat()` to append a row to a DataFrame:
```
import pandas as pd
# create an empty DataFrame
df = pd.DataFrame(columns=['用户数'])
# append a row to the DataFrame
time = 10
new_row = pd.DataFrame({'用户数': [time]})
df = pd.concat([df, new_row], ignore_index=True)
# print the updated DataFrame
print(df)
```
This should create a new DataFrame with one row containing the value of `time` in the `用户数` column. You can modify this code to fit your specific use case.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)