擅长:python、mysql、java
<h3>设置</h3>
<pre><code>idx = pd.MultiIndex.from_tuples([('maize_1', 'Temperate'), ('maize_1', 'Tropical'),
('maize_2', 'Tropical'), ('maize_2', 'Temperate'),
('soybean_1', 'Temperate'), ('soybean_1', 'Tropical')],
names=['Crop', 'Region'])
s = pd.Series([30., 46., 77.5, 13.5, 18.5, 34.], idx)
s
Crop Region
maize_1 Temperate 30.0
Tropical 46.0
maize_2 Tropical 77.5
Temperate 13.5
soybean_1 Temperate 18.5
Tropical 34.0
dtype: float64
</code></pre>
<h3>解决方案</h3>
<p>IIUC您想按<code>'Region'</code>排序,而不使用{<cd2>}。</p>
^{pr2}$
<p>您也可以按原样对索引排序,但它也将排序<code>'Crop'</code>。碰巧你的<code>'Crop'</code>已经按顺序排列好了。但如果不是这样的话,这个解决方案将保留这一点。</p>