'DataFrame' object has no attribute 'as_matrix'
时间: 2023-09-15 13:21:52 浏览: 63
Pandas库之DataFrame使用的学习笔记
The 'as_matrix' method has been deprecated in pandas since version 0.23.0 and removed in version 1.0.0. To convert a DataFrame to a NumPy array, you can use the 'values' attribute. For example:
```
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
array = df.values
print(array)
```
This will output:
```
array([[1, 4],
[2, 5],
[3, 6]])
```
Note that the resulting array will have the same data type as the original DataFrame. If you need to convert the data type, you can use the 'astype' method.
阅读全文