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 1 commit
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
16 changes: 14 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4411,9 +4411,13 @@ 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. Note that there could be multiple values returned for the selected
Copy link
Member

Choose a reason for hiding this comment

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

maybe add a paragraph break here?

axis (when more than one item share the maximum frequency), which is the
reason why a dataframe is returned. This means that if you want to impute
missing values with the mode in a dataframe df, you can just do this:
df.fillna(df.mode().ix[0])
Copy link
Member

Choose a reason for hiding this comment

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

two things:

  1. If you "quote" code with two backticks `` on each time it will be formatted as code in the online documentation.
  2. I would suggest using .iloc instead of .ix, because the later will fail if the index consists of integers.


Parameters
----------
Expand All @@ -4426,6 +4430,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