'list' object has no attribute 'apply'
时间: 2023-09-27 20:09:10 浏览: 124
The error message " 'list' object has no attribute 'apply' " usually occurs when you try to call the `apply()` method on a Python list object. The `apply()` method is not a built-in method for Python lists, but it is a method of pandas DataFrames and Series.
If you are trying to apply a function to each element of a list, you can use the built-in `map()` function instead. For example, if you have a list of numbers and you want to square each of them, you can do:
```
numbers = [1, 2, 3, 4, 5]
squared_numbers = list(map(lambda x: x**2, numbers))
```
This will apply the lambda function to each element of the `numbers` list and return a new list containing the squared numbers.
If you are working with pandas DataFrames or Series, you can use the `apply()` method to apply a function to each row or column of the DataFrame or Series. However, make sure that you are calling the `apply()` method on a pandas object, not a Python list.
阅读全文