Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to use pandas to find consecutive same data in time series

$
0
0

Here is a time series data like this,call it df:

'No''Date''Value'0     600000     1999-11-10    11     600000     1999-11-11    12     600000     1999-11-12    13     600000     1999-11-15    14     600000     1999-11-16    15     600000     1999-11-17    16     600000     1999-11-18    07     600000     1999-11-19    18     600000     1999-11-22    19     600000     1999-11-23    110    600000     1999-11-24    111    600000     1999-11-25    012    600001     1999-11-26    113    600001     1999-11-29    114    600001     1999-11-30    0

I want to get the date range of the consecutive 'Value' of 1, so how can I get the final result as follows:

'No''BeginDate''EndDate''Consecutive'0 600000    1999-11-10    1999-11-17    61 600000    1999-11-19    1999-11-24    42 600001    1999-11-26    1999-11-29    2

Viewing all articles
Browse latest Browse all 23131

Trending Articles