pyarrow.compute.mode#

pyarrow.compute.mode(array,/,n=1,*,skip_nulls=True,min_count=0,options=None,memory_pool=None)#

Compute the modal (most common) values of a numeric array.

Compute the n most common values and their respective occurrence counts.The output has typestruct<mode: T, count: int64>, where T is theinput type.The results are ordered by descendingcount first, and ascendingmodewhen breaking ties.Nulls are ignored. If there are no non-null values in the array,an empty array is returned.

Parameters:
arrayArray-like

Argument to compute function.

nint, default 1

Number of distinct most-common values to return.

skip_nullsbool, defaultTrue

Whether to skip (ignore) nulls in the input.If False, any null in the input forces the output to null.

min_countint, default 0

Minimum number of non-null values in the input. If the numberof non-null values is belowmin_count, the output is null.

optionspyarrow.compute.ModeOptions, optional

Alternative way of passing options.

memory_poolpyarrow.MemoryPool, optional

If not passed, will allocate memory from the default memory pool.

Examples

>>>importpyarrowaspa>>>importpyarrow.computeaspc>>>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)]>