Split a series on time gaps in pandas?

前端 未结 1 1634
情书的邮戳
情书的邮戳 2020-12-17 00:14

Is it possible to split a time series on it\'s gaps. For example, suppose we had the following:

rng2011 = pd.date_range(\'1/1/2011\', periods=72, freq=\'H\')         


        
相关标签:
1条回答
  • 2020-12-17 00:36

    Assuming Y is a column in your dataframe, one way is to use diff and cumsum:

    df = DataFrame(Y)
    df[1] = df[0].diff() > 600000000000.0 #nanoseconds in ten minutes
    df[1] = df[1].apply(lambda x: 1 if x else 0).cumsum()
    df.groupby(1)
    

    Note: If you use the number of nanoseconds in 72 hours it'll split into two groups.

    0 讨论(0)
提交回复
热议问题