Skip to content
Advertisement

How to get first and last value of each group in pandas with no group by column?

Hi Folks, I need to take first and last value from each group(where the counter value is 1 consecutively )

My Input :-

JavaScript

Desired Output :-

JavaScript

Advertisement

Answer

You can aggregate by consecutive 1 values with aggregate minimal and maximal TIMESTAMP:

JavaScript

EDIT: Test groups:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement