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)
| 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) |