擅长:python、mysql、java
<p>这被认为是一个回归错误,请参见<a href="https://github.com/pandas-dev/pandas/issues/33317" rel="nofollow noreferrer">GH33317</a>。好消息是,这是固定在熊猫1.1</p>
<pre><code>pd.__version__
# '1.1.0.dev0+2004.g8d10bfb6f'
pd.Series([1, pd.NA], dtype='Int8').value_counts(normalize=True)
1 1.0
dtype: float64
</code></pre>
<hr/>
<p><strong>更多示例</strong></p>
<pre><code>s = pd.Series([1, 1, 1, 2, 2, 3, pd.NA], dtype='Int8')
</code></pre>
<pre><code>s.value_counts()
1 3
2 2
3 1
dtype: Int64
s.value_counts(normalize=True)
1 0.500000
2 0.333333
3 0.166667
dtype: float64
s.value_counts(normalize=True, dropna=False)
1 0.428571
2 0.285714
NaN 0.142857
3 0.142857
dtype: float64
</code></pre>