pby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.mode  #

DataFrame.  mode  (  _ axis  =  0  _ , _ numeric_only  =  False  _ , _ dropna
=  True  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L11923-L12013) #

    

Get the mode(s) of each element along the selected axis.

The mode of a set of values is the value that appears most often. It can be
multiple values.

Parameters  :

    

**axis** {0 or âindexâ, 1 or âcolumnsâ}, default 0

    

The axis to iterate over while searching for the mode:

  * 0 or âindexâ : get mode of each column 

  * 1 or âcolumnsâ : get mode of each row. 

**numeric_only** bool, default False

    

If True, only apply to numeric columns.

**dropna** bool, default True

    

Donât consider counts of NaN/NaT.

Returns  :

    

DataFrame

    

The modes of each column or row.

See also

[ ` Series.mode  ` ](pandas.Series.mode.html#pandas.Series.mode
"pandas.Series.mode")

    

Return the highest frequency value in a Series.

[ ` Series.value_counts  `
](pandas.Series.value_counts.html#pandas.Series.value_counts
"pandas.Series.value_counts")

    

Return the counts of values in a Series.

Examples

    
    
    >>> df = pd.DataFrame([('bird', 2, 2),
    ...                    ('mammal', 4, np.nan),
    ...                    ('arthropod', 8, 0),
    ...                    ('bird', 2, np.nan)],
    ...                   index=('falcon', 'horse', 'spider', 'ostrich'),
    ...                   columns=('species', 'legs', 'wings'))
    >>> df
               species  legs  wings
    falcon        bird     2    2.0
    horse       mammal     4    NaN
    spider   arthropod     8    0.0
    ostrich       bird     2    NaN
    

By default, missing values are not considered, and the mode of wings are both
0 and 2. Because the resulting DataFrame has two rows, the second row of `
species  ` and ` legs  ` contains ` NaN  ` .

    
    
    >>> df.mode()
      species  legs  wings
    0    bird   2.0    0.0
    1     NaN   NaN    2.0
    

Setting ` dropna=False  ` ` NaN  ` values are considered and they can be the
mode (like for wings).

    
    
    >>> df.mode(dropna=False)
      species  legs  wings
    0    bird     2    NaN
    

Setting ` numeric_only=True  ` , only the mode of numeric columns is computed,
and columns of other types are ignored.

    
    
    >>> df.mode(numeric_only=True)
       legs  wings
    0   2.0    0.0
    1   NaN    2.0
    

To compute the mode over columns and not rows, use the axis parameter:

    
    
    >>> df.mode(axis='columns', numeric_only=True)
               0    1
    falcon   2.0  NaN
    horse    4.0  NaN
    spider   0.0  8.0
    ostrich  2.0  NaN
    

[ __ previous  pandas.DataFrame.min  ](pandas.DataFrame.min.html "previous
page") [ next  pandas.DataFrame.pct_change  __
](pandas.DataFrame.pct_change.html "next page")

__ On this page

  * ` DataFrame.mode()  `

[ __ Show Source ](../../_sources/reference/api/pandas.DataFrame.mode.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.