'DataFrame' object has no attribute 'as_matrix
时间: 2023-09-18 20:10:40 浏览: 145
Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
5星 · 资源好评率100%
The error message "AttributeError: 'DataFrame' object has no attribute 'as_matrix'" means that you are trying to access the 'as_matrix' attribute of a Pandas DataFrame object, but this attribute does not exist. The 'as_matrix' method was removed in Pandas version 0.24.0, as it was deemed to be confusing and potentially dangerous.
To fix this error, you can replace the 'as_matrix' method with the 'values' property, which returns the underlying NumPy array of the DataFrame. For example, if you have a DataFrame called 'df', you would replace:
```
X = df.as_matrix()
```
with:
```
X = df.values
```
This should solve the error and allow you to access the values of the DataFrame.
阅读全文