Reputation: 2773
(Not a duplicate question)
I have the following dataset with Gmt time
and Open
value
Gmt time, Open
2018-01-01 00:00:00,2.7321
2018-01-01 00:01:00,2.7323
2018-01-01 00:02:00,2.7322
2018-01-01 00:03:00,2.7321
2018-01-01 00:04:00,2.7323
2018-01-01 00:05:00,2.7325
2018-01-01 00:06:00,2.7322
...., ....
2018-12-31 23:59:00,3.1463
The Gmt time
is a DateTime
with yyyy-mm-dd hh:mm:ss
given above.
You can see that each data point is 1 minute
apart.
I want to find the highest Open
value and the lowest Open
value for every single day(24hours time frame). Eg: 2018-01-01 00:00:00
to 2018-01-01 23:59:00
My new DataFrame
should look like this:
Gmt time, Open-high, Open-Low
2018-01-01 ,2.7321, ,2.7321
2018-01-02 ,2.7321, ,2.7321
2018-01-03 ,2.7321, ,2.7321
...., ...., ...., ....
2018-12-31 ,2.7321, ,2.7321
Could you please let me know how can I do this in pandas?
Upvotes: 0
Views: 345
Reputation: 150735
I would be surprised if it is not a dup:
df.groupby(df['Gmt time'].dt.floor('D')).Open.agg(['min','max']).reset_index()
output:
Gmt time min max
0 2018-01-01 2.7321 2.7325
1 2018-12-31 3.1463 3.1463
Upvotes: 2