| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/../generated/pyarrow.compute.first_last.html | [Back] [Original] |
Section Navigation
Compute the first and last values of an array.
Null values are ignored by default. If skip_nulls = false, then this will return the first and last values regardless if it is null
Argument to compute function.
TrueWhether to skip (ignore) nulls in the input. If False, any null in the input forces the output to null.
int, default 1Minimum 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.ScalarAggregateOptions, 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
>>> arr1 = pa.array([1, 1, 2, 2, 3, 2, 2, 2])
>>> pc.first_last(arr1)
<pyarrow.StructScalar: [('first', 1), ('last', 2)]>
Using skip_nulls to handle null values.
>>> arr2 = pa.array([None, 2.0, 3.0, None])
>>> pc.first_last(arr2)
<pyarrow.StructScalar: [('first', 2.0), ('last', 3.0)]>
>>> pc.first_last(arr2, skip_nulls=False)
<pyarrow.StructScalar: [('first', None), ('last', None)]>
Using ScalarAggregateOptions to control minimum number of non-null values.
>>> arr3 = pa.array([1.0, None, float("nan"), 3.0])
>>> pc.first_last(arr3)
<pyarrow.StructScalar: [('first', 1.0), ('last', 3.0)]>
>>> pc.first_last(arr3, options=pc.ScalarAggregateOptions(min_count=3))
<pyarrow.StructScalar: [('first', 1.0), ('last', 3.0)]>
>>> pc.first_last(arr3, options=pc.ScalarAggregateOptions(min_count=4))
<pyarrow.StructScalar: [('first', None), ('last', None)]>
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 |