Groupby To Return Nth Group - NOT Row
I'm attempting to group by two factors in a long (>2M) rows. Background to the data The second factor is effectively a test date - for a given sample (the first group) a sample
Solution 1:
You can reset_index
, then use GroupBy
+ nth
:
res = df.reset_index().groupby('id').nth(1)
print(res)
date value
id
1 10/01/2017 15:45:00 [0.01, 0.4]
3 06/01/2017 11:02:00 [0.1]
5 05/01/2017 10:09:00 [0.01]
6 03/02/2017 09:15:00 [0.5]
7 19/01/2017 16:34:00 [0.1]
Post a Comment for "Groupby To Return Nth Group - NOT Row"