pyspark.pandas.groupby.GroupBy.last

GroupBy.last(numeric_only: Optional[bool] = False, min_count: int = - 1) → FrameLike[source]

Compute last of group values.

New in version 3.3.0.

Parameters
numeric_onlybool, default False

Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data.

New in version 3.4.0.

min_countint, default -1

The required number of valid values to perform the operation. If fewer than min_count non-NA values are present the result will be NA.

New in version 3.4.0.

Examples

>>> df = ps.DataFrame({"A": [1, 2, 1, 2], "B": [True, False, False, True],
...                    "C": [3, 3, 4, 4], "D": ["a", "a", "b", "a"]})
>>> df
   A      B  C  D
0  1   True  3  a
1  2  False  3  a
2  1  False  4  b
3  2   True  4  a
>>> df.groupby("A").last().sort_index()
       B  C  D
A
1  False  4  b
2   True  4  a

Include only float, int, boolean columns when set numeric_only True.

>>> df.groupby("A").last(numeric_only=True).sort_index()
       B  C
A
1  False  4
2   True  4
>>> df.groupby("D").last().sort_index()
   A      B  C
D
a  2   True  4
b  1  False  4
>>> df.groupby("D").last(min_count=3).sort_index()
     A     B    C
D
a  2.0  True  4.0
b  NaN  None  NaN