Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
dataframe.mode() function gets the mode(s) of each element along the axis selected. Adds a row for each mode per label, fills in gaps with nan. 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.
Syntax: DataFrame.mode(axis=0, numeric_only=False)
axis : get mode of each column1, get mode of each row
numeric_only : if True, only apply to numeric columns
Returns : modes : DataFrame (sorted)
Example #1: Use
mode() function to find the mode over the index axis.
Lets use the
dataframe.mode() function to find the mode of dataframe
Example #2: Use
mode() function to find the mode over the column axis
Lets use the
dataframe.mode() function to find the mode
In the 0th and 3rd row, 14 and 3 is the mode, as they have the maximum occurrence (i.e. 2). In rest of the column all element are mode because they have the same frequency of occurrence.
- Python | pandas.to_markdown() in Pandas
- Python | pandas.map()
- Python | Pandas Series.mean()
- Python | Pandas dataframe.sem()
- Python | Pandas dataframe.max()
- Python | Pandas DataFrame.ix[ ]
- Python | Pandas Series.take()
- Python | Pandas.to_datetime()
- Python | Pandas dataframe.mean()
- Python | Pandas DatetimeIndex.second
- Python | Pandas TimedeltaIndex.contains
- Python | Pandas DatetimeIndex.day
- Python | Pandas Series.sum()
- Python | Pandas dataframe.std()
- Python | Pandas Series.abs()
- Python | Pandas Series.div()
- Python | Pandas DataFrame.loc
- Python | Pandas Series.ptp()
- Python | Pandas Index.where
- Python | Pandas Series.mul()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.