擅长:python、mysql、java
<p>如果您想用<code>pivot_table()</code>来做:</p>
<pre><code>In [169]: x.pivot_table(index=[x.index,'year'], values='SURQ').reset_index()
Out[169]:
unit year SURQ
0 10001 2012 89
1 10001 2013 75
2 10001 2014 36
3 10002 2012 83
4 10002 2013 69
5 10002 2014 59
6 10003 2012 88
7 10003 2013 59
8 10003 2014 84
</code></pre>
<p>但是我认为使用<code>groupby()</code>会更快,需要更少的内存</p>
<p>数据:</p>
<pre><code>In [168]: x
Out[168]:
year SURQ
unit
10001 2012 89
10002 2012 83
10003 2012 88
10001 2013 75
10002 2013 69
10003 2013 59
10001 2014 36
10002 2014 59
10003 2014 84
</code></pre>