擅长:python、mysql、java
<p>在pandas v0.22中,可以使用unstack特性。在上面@Kumar answer的基础上,您可以使用pandas stack/unstack特性来处理它的变化。</p>
<pre><code>from io import StringIO
import pandas as pd
df = pd.read_csv(StringIO("""name,prop
A,1
A,2
B, 4
A, 3
B, 5
B, 2"""))
df.shape
df
temp = df.groupby(['name'])['prop'].describe()
temp
temp.stack() #unstack(),unstack(level=-1) level can be -1, 0
</code></pre>
<p>查看文档<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.unstack.html" rel="nofollow noreferrer">pandas unstack</a>了解更多详细信息</p>