How to find the start time and end time of an event in python?

后端 未结 3 1065
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 11:22

I have a data frame consists of column 1 i.e event and column 2 is Datetime:

Sample data

 Event   Time
    0   2020-02-12 11:00:00
    0   2020-02-12 11         


        
3条回答
  •  执念已碎
    2021-01-27 12:16

    Use group by and agg to get the output in desired format.

    df =pd.DataFrame([['0',11],['1',12],['1',13],['0',15],['1',16],['3',11]],columns=['Event','Time'] )
    df.groupby(['Event']).agg(['first','last']).rename(columns={'first':'start-event','last':'end-event'})
    

    Output:

    Event start-event   end-event   
    0      11           15
    1      12           16
    3      11           11
    

提交回复
热议问题