Skip to content

BUG: groupby.first/last with nans #8427

Closed
@jreback

Description

@jreback

This is incorrect, as this is applied column by column (as they are different dtypes)
so _first_compat should first compute the mask then use it.

from SO

In [18]: df = pd.DataFrame([{'id':"a",'val':np.nan, 'val2':-1},{'id':"a",'val':'TREE','val2':15}])

In [19]: df
Out[19]: 
  id   val  val2
0  a   NaN    -1
1  a  TREE    15

In [20]: df.groupby('id').first()
Out[20]: 
     val  val2
id            
a   TREE    -1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions