擅长:python、mysql、java
<p>这可能是一个带有<code>pd.Series.groupby</code>的bug,我将在pandas中为此案例提交一个bug报告。在</p>
<p>解决方法#1使用pd数据帧而不是pd系列在</p>
<pre><code>data[['N']].groupby(['date','name']).sum()
</code></pre>
<p>输出:</p>
^{pr2}$
<p>“按工作级别使用”参数</p>
<pre><code>data['N'].groupby(level=[0,2]).sum()
</code></pre>
<p>输出:</p>
<pre><code>date name
2016-02-15 A 5
Name: N, dtype: int64
</code></pre>
<p>解决方法3使用带有聚合器列的数据帧:</p>
<pre><code> data.groupby(['date', 'name'])['N'].sum()
</code></pre>
<p>输出:</p>
<pre><code>date name
2016-02-15 A 5
Name: N, dtype: int64
</code></pre>