将数据框转换为矩阵形式

``````state VDM  MDM  OM
AP     1    2   5
GOA    1    2   1
GU     1    2   4
KA     1    5   1
MA     1    4   4
``````

``````aMat=df1000.as_matrix()
print(aMat)
``````

``````[['AP' 1 2 5]
['GOA' 1 2 1]
['GU' 1 2 4]
['KA' 1 5 1]
['MA' 1 4 4]]
``````

``````[[1, 2, 5], [1, 2, 1], [1,  2,  4], [1, 5, 1], [1, 4, 4]]
``````

• Jerey 回复

Select all columns without first by `DataFrame.iloc` and convert integer values to strings by `DataFrame.astype`, last convert to numpy array by `to_numpy` or `DataFrame.values`:

``````#pandas 0.24+
aMat=df1000.iloc[:, 1:].astype(str).to_numpy()
#pandas below
aMat=df1000.iloc[:, 1:].astype(str).values
``````

Or remove first column by `DataFrame.drop`:

``````#pandas 0.24+
aMat=df1000.drop('state', axis=1).astype(str).to_numpy()
#pandas below
aMat=df1000.drop('state', axis=1).astype(str).values
``````

• 叛逆 回复

You can use `df.iloc[]`:

``````df.iloc[:,1:].to_numpy()
``````
``````array([[1, 2, 5],
[1, 2, 1],
[1, 2, 4],
[1, 5, 1],
[1, 4, 4]], dtype=int64)
``````

或用于字符串矩阵：

``````df.astype(str).iloc[:,1:].to_numpy()
``````
``````array([['1', '2', '5'],
['1', '2', '1'],
['1', '2', '4'],
['1', '5', '1'],
['1', '4', '4']], dtype=object)
``````

Note why we are not using `as_matrix()`

“ .as_matrix将在将来的版本中删除。请改用.values。”