AttributeError: 'list' object has no attribute 'iterrows'
时间: 2023-09-22 19:10:11 浏览: 424
This error occurs when you try to use the iterrows method on a list object. However, the iterrows method is only available for pandas dataframes and series.
To fix this error, you need to convert the list object to a pandas dataframe or series before using the iterrows method. You can do this by using the pd.DataFrame() or pd.Series() function in pandas.
For example:
```python
import pandas as pd
my_list = [1, 2, 3, 4]
# Convert list to pandas series
my_series = pd.Series(my_list)
# Use iterrows method on series
for index, value in my_series.iterrows():
print(index, value)
```
Alternatively, if you do not need to use the iterrows method, you can loop through the list using a for loop:
```python
my_list = [1, 2, 3, 4]
for value in my_list:
print(value)
```
阅读全文