pandas.Series.mode #

系列。模式( dropna = True ) [来源] #

返回系列的模式。

众数是最常出现的值。可以有多种模式。

即使只返回一个值,也始终返回 Series。

参数
dropna bool,默认 True

不考虑 NaN/NaT 的计数。

返回
系列

系列模式按排序顺序排列。

例子

>>> s = pd.Series([2, 4, 2, 2, 4, None])
>>> s.mode()
0    2.0
dtype: float64

多种模式:

>>> s = pd.Series([2, 4, 8, 2, 4, None])
>>> s.mode()
0    2.0
1    4.0
dtype: float64

考虑和不考虑空值:

>>> s = pd.Series([2, 4, None, None, 4, None])
>>> s.mode(dropna=False)
0   NaN
dtype: float64
>>> s = pd.Series([2, 4, None, None, 4, None])
>>> s.mode()
0    4.0
dtype: float64