擅长:python、mysql、java
<p>看起来您的数据帧的<code>Education</code>列中必须有混合类型。错误消息告诉您,它无法将字符串<em>与列中的浮点数进行比较。假设您想对值进行数字排序,您可以将它们转换为整数类型,然后<em>然后</em>排序。我建议您无论如何这样做,因为混合类型对于数据帧中的任何操作都不会太有用。然后使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html" rel="noreferrer">^{<cd2>}</a>。</p>
<pre><code>suicide_data['Education'] = suicide_data['Education'].astype('int')
suicide_data.sort_values(by='Education')
</code></pre>
<hr/>
<p>值得指出的是,你的第一次尝试</p>
<pre><code>suicide_data.sort_index(axis=0, kind='mergesort')
</code></pre>
<p>将根据索引对数据帧进行排序,这是您不需要的,并且您将进行第二次尝试</p>
<pre><code>suicide_data.Education.sort_values()
</code></pre>
<p>只会返回已排序的序列-它们是完全无效的方法。</p>