Skip to content

Added documentation for mode() #9769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4411,9 +4411,15 @@ def _get_agg_axis(self, axis_num):

def mode(self, axis=0, numeric_only=False):
"""
Gets the mode of each element along the axis selected. Empty if nothing
Gets the mode(s) of each element along the axis selected. Empty if nothing
has 2+ occurrences. Adds a row for each mode per label, fills in gaps
with nan.
with nan.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually need a full empty line to make a new paragraph :)


Note that there could be multiple values returned for the selected
axis (when more than one item share the maximum frequency), which is the
reason why a dataframe is returned. If you want to impute missing values
with the mode in a dataframe ``df``, you can just do this:
``df.fillna(df.mode().iloc[0])``

Parameters
----------
Expand All @@ -4426,6 +4432,14 @@ def mode(self, axis=0, numeric_only=False):
Returns
-------
modes : DataFrame (sorted)

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2, 1, 2, 1, 2, 3]})
>>> df.mode()
A
0 1
1 2
"""
data = self if not numeric_only else self._get_numeric_data()
f = lambda s: s.mode()
Expand Down