擅长:python、mysql、java
<p>一种方法是首先执行<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow">^{<cd1>}</a>,重置<code>temp</code>数据帧的索引,然后根据需要使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot.html" rel="nofollow">^{<cd3>}</a>。示例-</p>
<pre><code>In [24]: df = pd.read_csv(io.StringIO("""name,prop
....: A,1
....: A,2
....: B, 4
....: A, 3
....: B, 5
....: B, 2"""))
In [25]: temp = df.groupby('name')['prop'].describe().reset_index()
In [26]: newdf = temp.pivot(index='name',columns='level_1',values=0)
In [27]: newdf.columns.name = '' #This is needed so that the name of the columns is not `'level_1'` .
In [28]: newdf
Out[28]:
25% 50% 75% count max mean min std
name
A 1.5 2 2.5 3 3 2.000000 1 1.000000
B 3.0 4 4.5 3 5 3.666667 2 1.527525
</code></pre>
<p>然后您可以将这个<code>newdf</code>保存到csv。</p>