0

this is my question and I've spent a lot of time with this...

My dataframe is:

idx value                   timestamp
0   2070.0 2020-03-16 10:21:00.667138+00:00
1   2070.0 2020-03-16 10:20:00.667138+00:00
2   2070.0 2020-03-16 10:19:00.667138+00:00
3   2070.0 2020-03-16 10:18:00.667138+00:00
4   2060.0 2020-03-16 10:17:00.667138+00:00
5   2060.0 2020-03-16 10:16:00.667138+00:00
6   2060.0 2020-03-16 10:15:00.667138+00:00
7   2060.0 2020-03-16 10:14:00.667138+00:00
8   2050.0 2020-03-16 10:13:00.667138+00:00
9   2050.0 2020-03-16 10:12:00.667138+00:00
10  2050.0 2020-03-16 10:11:00.667138+00:00
11  2050.0 2020-03-16 10:10:00.667138+00:00

and using the groupby() i can't get the group by value and the range period from group.

I need to get:

idx   value    intial         final
0     2070    10:21:00      10:17:00
1     2060    10:17:00      10:13:00
2     2050    10:13:00      10:10:00

any help will be appreciated

1 Answers1

0

The groupby() requires another method chained, such as sum(), mean() or any other. What can work for you is something like this:

df2['initial']=df.groupby('value').min()['timestamp']
df2['final']=df.groupby('value').max()['timestamp']

But you still will require to process the date data to extract the hour. This Link explains how to do that.

rossberto
  • 97
  • 5