擅长:python、mysql、java
<p>编辑:<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.as_matrix.html" rel="nofollow noreferrer" title="documentation reference">^{<cd1>} is deprecated since version 0.23.0</a></p>
<p>您可以在数据帧上使用内置的<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.values.html#pandas.DataFrame.values" rel="nofollow noreferrer">^{<cd2>}</a>或<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy" rel="nofollow noreferrer">^{<cd3>}</a>(推荐选项)方法:</p>
<pre><code>In [8]:
df.to_numpy()
Out[8]:
array([[ 0.9, 7. , 5.2, ..., 13.3, 13.5, 8.9],
[ 0.9, 7. , 5.2, ..., 13.3, 13.5, 8.9],
[ 0.8, 6.1, 5.4, ..., 15.9, 14.4, 8.6],
...,
[ 0.2, 1.3, 2.3, ..., 16.1, 16.1, 10.8],
[ 0.2, 1.3, 2.4, ..., 16.5, 15.9, 11.4],
[ 0.2, 1.3, 2.4, ..., 16.5, 15.9, 11.4]])
</code></pre>
<p>如果您明确想要列表而不是numpy数组,请添加<code>.tolist()</code>:</p>
<pre><code>df.to_numpy().tolist()
</code></pre>