cudf.DataFrame.mode#

DataFrame.mode(axis=0, numeric_only=False, dropna=True)[source]#

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_onlybool, default False

If True, only apply to numeric columns.

dropnabool, default True

Don’t consider counts of NA/NaN/NaT.

Returns:
DataFrame

The modes of each column or row.

See also

cudf.Series.mode

Return the highest frequency value in a Series.

cudf.Series.value_counts

Return the counts of values in a Series.

Examples

>>> import cudf
>>> df = cudf.DataFrame({
...     "species": ["bird", "mammal", "arthropod", "bird"],
...     "legs": [2, 4, 8, 2],
...     "wings": [2.0, None, 0.0, None]
... })
>>> df
     species  legs wings
0       bird     2   2.0
1     mammal     4  <NA>
2  arthropod     8   0.0
3       bird     2  <NA>

By default, missing values are not considered, and the mode of wings are both 0 and 2. The second row of species and legs contains NA, because they have only one mode, but the DataFrame has two rows.

>>> df.mode()
  species  legs  wings
0    bird     2    0.0
1    <NA>  <NA>    2.0

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

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

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
1  <NA>    2.0

Pandas Compatibility Note

pandas.DataFrame.transpose()

axis parameter is currently not supported.