Ad

Ungrouping Group By Object By Taking The First Value In Dataframe Pandas

- 1 answer

I have dataframe s which is a group by object:

s = df.groupby(['x','y'])

I would like to take the first event in each output to a new dataframe, I have tried:

s.first().reset_index()

I would like to take the keys of the group by table and putting the values back into a dataframe (ungrouping)

Ad

Answer

df.groupby(['x','y'], as_index=False).first()
Ad
source: stackoverflow.com
Ad