pyarrow.compute.last#
- pyarrow.compute.last(array, /, *, skip_nulls=True, min_count=1, options=None, memory_pool=None)#
Compute the first value in each group.
Null values are ignored by default. If skip_nulls = false, then this will return the first and last values regardless if it is null
- Parameters:
- arrayArray-like
Argument to compute function.
- skip_nullsbool, default
True Whether to skip (ignore) nulls in the input. If False, any null in the input forces the output to null.
- min_count
int, default 1 Minimum number of non-null values in the input. If the number of non-null values is below min_count, the output is null.
- options
pyarrow.compute.ScalarAggregateOptions, optional Alternative way of passing options.
- memory_pool
pyarrow.MemoryPool, optional If not passed, will allocate memory from the default memory pool.
Examples
>>> import pyarrow as pa >>> import pyarrow.compute as pc >>> arr1 = pa.array([1, 1, 2, 2, 3, 2, 2, 2]) >>> pc.last(arr1) <pyarrow.Int64Scalar: 2>
Using
skip_nullsto handle null values.>>> arr2 = pa.array([1.0, 2.0, 3.0, None]) >>> pc.last(arr2) <pyarrow.DoubleScalar: 3.0> >>> pc.last(arr2, skip_nulls=False) <pyarrow.DoubleScalar: None>
Using
ScalarAggregateOptionsto control minimum number of non-null values.>>> arr3 = pa.array([1.0, None, float("nan"), 3.0]) >>> pc.last(arr3) <pyarrow.DoubleScalar: 3.0> >>> pc.last(arr3, options=pc.ScalarAggregateOptions(min_count=3)) <pyarrow.DoubleScalar: 3.0> >>> pc.last(arr3, options=pc.ScalarAggregateOptions(min_count=4)) <pyarrow.DoubleScalar: None>