-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
CategoricalCategorical Data TypeCategorical Data TypeGroupbyMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolatenp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone
Description
Was looking to consolidate nth, first and last in the GroupBy world but was hitting some issues with categorical tests and handling of missing data. Note that the following calls are not equivalent, though they should be:
>>> import numpy as np
>>> import pandas as pd
>>> s1 = pd.Categorical([np.nan, 'a', np.nan, 'a'], categories=['a', 'b', 'c'])
>>> s2 = pd.Series([1, 2, 3, 4])
>>> df = pd.DataFrame({'s1': s1, 's2': s2})
>>> grp = df.groupby('s1', observed=False)
>>> grp.first()
s2
s1
a 2.0
b NaN
c NaN
>>> grp.nth(0)
s2
s1
a 2
Metadata
Metadata
Assignees
Labels
CategoricalCategorical Data TypeCategorical Data TypeGroupbyMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolatenp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate