| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/../generated/../generated/pyarrow.compute.mode.html | [Back] [Original] |
Section Navigation
Compute the modal (most common) values of a numeric array.
Compute the n most common values and their respective occurrence counts. The output has type struct<mode: T, count: int64>, where T is the input type. The results are ordered by descending count first, and ascending mode when breaking ties. Nulls are ignored. If there are no non-null values in the array, an empty array is returned.
Argument to compute function.
int, default 1Number of distinct most-common values to return.
TrueWhether to skip (ignore) nulls in the input. If False, any null in the input forces the output to null.
int, default 0Minimum number of non-null values in the input. If the number of non-null values is below min_count, the output is null.
pyarrow.compute.ModeOptions, optionalAlternative way of passing options.
pyarrow.MemoryPool, optionalIf not passed, will allocate memory from the default memory pool.
Examples
>>> import pyarrow as pa
>>> import pyarrow.compute as pc
>>> arr = pa.array([1, 1, 2, 2, 3, 2, 2, 2])
>>> modes = pc.mode(arr, 2)
>>> modes[0]
<pyarrow.StructScalar: [('mode', 2), ('count', 5)]>
>>> modes[1]
<pyarrow.StructScalar: [('mode', 1), ('count', 2)]>
Copyright 2016-2026 Apache Software Foundation.
Apache Arrow, Arrow, Apache, the Apache logo, and the Apache Arrow project logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.
Created using Sphinx 9.1.0.
Built with the PyData Sphinx Theme 0.20.0.
| Web Proxy Viewer | New URL | Original Page |