MCPcopy
hub / github.com/pandas-dev/pandas / mode

Method mode

pandas/core/series.py:2093–2161  ·  view source on GitHub ↗

Return the mode(s) of the Series. The mode is the value that appears most often. There can be multiple modes. Always returns Series even if only one value is returned. Parameters ---------- dropna : bool, default True Don't consider cou

(self, dropna: bool = True)

Source from the content-addressed store, hash-verified

2091 return maybe_unbox_numpy_scalar(notna(self._values).sum().astype("int64"))
2092
2093 def mode(self, dropna: bool = True) -> Series:
2094 """
2095 Return the mode(s) of the Series.
2096
2097 The mode is the value that appears most often. There can be multiple modes.
2098
2099 Always returns Series even if only one value is returned.
2100
2101 Parameters
2102 ----------
2103 dropna : bool, default True
2104 Don't consider counts of NaN/NaT.
2105
2106 Returns
2107 -------
2108 Series
2109 Modes of the Series in sorted order.
2110
2111 See Also
2112 --------
2113 numpy.mode : Equivalent numpy function for computing median.
2114 Series.sum : Sum of the values.
2115 Series.median : Median of the values.
2116 Series.std : Standard deviation of the values.
2117 Series.var : Variance of the values.
2118 Series.min : Minimum value.
2119 Series.max : Maximum value.
2120
2121 Examples
2122 --------
2123 >>> s = pd.Series([2, 4, 2, 2, 4, None])
2124 >>> s.mode()
2125 0 2.0
2126 dtype: float64
2127
2128 More than one mode:
2129
2130 >>> s = pd.Series([2, 4, 8, 2, 4, None])
2131 >>> s.mode()
2132 0 2.0
2133 1 4.0
2134 dtype: float64
2135
2136 With and without considering null value:
2137
2138 >>> s = pd.Series([2, 4, None, None, 4, None])
2139 >>> s.mode(dropna=False)
2140 0 NaN
2141 dtype: float64
2142 >>> s = pd.Series([2, 4, None, None, 4, None])
2143 >>> s.mode()
2144 0 4.0
2145 dtype: float64
2146 """
2147 # TODO: Add option for bins like value_counts()
2148 values = self._values
2149 if isinstance(values, np.ndarray):
2150 res_values, _ = algorithms.mode(values, dropna=dropna)

Callers 15

test_mode_singleMethod · 0.95
test_number_modeMethod · 0.95
test_strobj_modeMethod · 0.95
test_datelike_modeMethod · 0.95
test_timedelta_modeMethod · 0.95
test_mixed_dtypeMethod · 0.95
test_uint64_overflowMethod · 0.95
test_mode_nullable_dtypeFunction · 0.95

Calls 3

_constructorMethod · 0.95
__finalize__Method · 0.80
_modeMethod · 0.45

Tested by 15

test_mode_singleMethod · 0.76
test_number_modeMethod · 0.76
test_strobj_modeMethod · 0.76
test_datelike_modeMethod · 0.76
test_timedelta_modeMethod · 0.76
test_mixed_dtypeMethod · 0.76
test_uint64_overflowMethod · 0.76
test_mode_nullable_dtypeFunction · 0.76