擅长:python、mysql、java
<p>好的,因为现在的答案之一是标记为这个问题的副本,我将在这里回答。</p>
<p>使用<a href="https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.wide_to_long.html" rel="nofollow noreferrer">^{<cd1>}</a></p>
<pre><code>pd.wide_to_long(df, ['key'], 'topic', 'age').reset_index().drop('age',1)
Out[123]:
topic key
0 8 abc
1 9 xab
2 8 def
3 9 xcd
4 8 ghi
5 9 xef
</code></pre>