ENH: Add skipna to groupby.first and groupby.last #57019
Labels
Enhancement
Groupby
Regression
Functionality that used to work in a prior pandas version
Transformations
e.g. cumsum, diff, rank
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Edit[rhshadrach]: This bug report has been reworked into an enhancement request. See the discussion below.
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
DataFrameGroupBy.transform
no longer supports"nth", n=0
as an argument.I assume this is related to the general push to limit what is allowed to be passed to
transform
to only operations that return a single row per group, and the fact that"nth"
can return multiple rows ifn
is alist
or such.Unfortunately,
"first"
is not an acceptable alternative because it removesNaN
s, which might not be desired. The current work around is something likelambda g: g.iloc[0]
but this forces us to use UDFs which are slow.I apologise if this has already been discussed, I tried to look for related content but couldn't find anything. If it is, I would be happy to turn this into a feature request for something like an update to
first
to allow it to not filter outNaN
s.Expected Behavior
The above code would return the 1st row from each group, not ignoring
NaN
s, i.e.Installed Versions
The text was updated successfully, but these errors were encountered: