擅长:python、mysql、java
<p><strong>熊猫0.23</strong>终于让你到了-D</p>
<p>现在可以将索引名(而不仅仅是列名)作为参数传递给<code>sort_values</code>。所以,这一行是有效的:</p>
<pre><code>df = df.sort_values(by = ['MyCol', 'MyIdx'], ascending = [False, True])
</code></pre>
<p>如果索引当前未命名:</p>
<pre><code>df = df.rename_axis('MyIdx').sort_values(by = ['MyCol', 'MyIdx'], ascending = [False, True])
</code></pre>