擅长:python、mysql、java
<p>有一个问题,您的列<code>bar</code>不是数字,所以聚合函数会忽略它。在</p>
<p>您可以检查省略列的<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dtype.html" rel="nofollow noreferrer">^{<cd2>}</a>不是数字:</p>
<pre><code>print (df['bar'].dtype)
object
</code></pre>
<p>您可以检查<a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html#automatic-exclusion-of-nuisance-columns" rel="nofollow noreferrer">automatic exclusion of nuisance columns</a>。在</p>
<p>解决方案是在将<code>string</code>值聚合为<code>numeric</code>之前,如果不可能,请使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_numeric.html" rel="nofollow noreferrer">^{<cd6>}</a>和参数<code>errors='coerce'</code>添加{<cd5>}:</p>
^{pr2}$
<p>但如果有混合数据-数字与<code>strings</code>是可能的,请使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.replace.html" rel="nofollow noreferrer">^{<cd9>}</a>:</p>
<pre><code>df['bar'] = df['bar'].replace("NULL", np.nan)
</code></pre>