'list' object has no attribute 'iloc'
时间: 2023-09-16 15:11:23 浏览: 145
python报错: 'list' object has no attribute 'shape'的解决
5星 · 资源好评率100%
The error message "'list' object has no attribute 'iloc'" occurs when you try to use the .iloc method on a Python list. The .iloc method is a pandas DataFrame method used to retrieve rows or columns by their integer positions.
To fix this error, you need to make sure that you are using a pandas DataFrame instead of a Python list. You can convert a list to a DataFrame using the pd.DataFrame() method.
For example, if you have a list called my_list, you can convert it to a DataFrame using the following code:
```
import pandas as pd
my_list = [1, 2, 3, 4, 5]
df = pd.DataFrame(my_list)
```
Now you can use the .iloc method on the DataFrame:
```
df.iloc[0] # returns the first row of the DataFrame
```
阅读全文