Skip to content

Commit 3273453

Browse files
committed
Added documentation for mode()
This relates to issue #9750
1 parent cb8c130 commit 3273453

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pandas/core/frame.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -4411,9 +4411,13 @@ def _get_agg_axis(self, axis_num):
44114411

44124412
def mode(self, axis=0, numeric_only=False):
44134413
"""
4414-
Gets the mode of each element along the axis selected. Empty if nothing
4414+
Gets the mode(s) of each element along the axis selected. Empty if nothing
44154415
has 2+ occurrences. Adds a row for each mode per label, fills in gaps
4416-
with nan.
4416+
with nan. Note that there could be multiple values returned for the selected
4417+
axis (when more than one item share the maximum frequency), which is the
4418+
reason why a dataframe is returned. This means that if you want to impute
4419+
missing values with the mode in a dataframe df, you can just do this:
4420+
df.fillna(df.mode().ix[0])
44174421
44184422
Parameters
44194423
----------
@@ -4426,6 +4430,14 @@ def mode(self, axis=0, numeric_only=False):
44264430
Returns
44274431
-------
44284432
modes : DataFrame (sorted)
4433+
4434+
Examples
4435+
--------
4436+
>>> df = pd.DataFrame({'A': [1, 2, 1, 2, 1, 2, 3]})
4437+
>>> df.mode()
4438+
A
4439+
0 1
4440+
1 2
44294441
"""
44304442
data = self if not numeric_only else self._get_numeric_data()
44314443
f = lambda s: s.mode()

0 commit comments

Comments
 (0)