擅长:python、mysql、java
<p>以下命令(来自<a href="https://stackoverflow.com/questions/48636363/how-can-i-unstack-without-sorting-in-pandas">how can i unstack without sorting in pandas?</a>)对我来说没问题:</p>
<pre class="lang-py prettyprint-override"><code>print(df.unstack(0).reindex(pd.unique(df.index.get_level_values(1))).sort_index(axis=1,level=1).T)
</code></pre>
<p>并返回:</p>
<pre><code> A C B
2017 1 1 2
2018 1 1 2
</code></pre>