擅长:python、mysql、java
<p>我想你需要<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow">^{<cd1>}</a>和<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow">^{<cd2>}</a>:</p>
<pre><code>df.set_index(['Entity_Name','State_Name','State_Group','State_Type'], inplace=True)
df.sort_index(inplace=True)
</code></pre>
<p>样品:</p>
<pre><code>df = pd.DataFrame({'State_Value':[4,5,6],
'State_Type':[7,1,2],
'State_Group':[1,3,5],
'State_Name':[5,3,1],
'Entity_Name':[7,7,7]})
df.set_index(['Entity_Name','State_Name','State_Group','State_Type'], inplace=True)
df.sort_index(inplace=True)
print (df)
State_Value
Entity_Name State_Name State_Group State_Type
7 1 5 2 6
3 3 1 5
5 1 7 4
</code></pre>