Premium problem55. Hourly OHLC Aggregation

Medium Locked

Given intraday stock data df with a datetime column 'time' and a 'price' column, bucket the rows into hourly intervals and compute, for each hour, the opening, highest, lowest, and closing price. Return a DataFrame indexed by the start of each hour with columns open, high, low, close.

Input

                 time  price
0 2020-01-01 09:15:00  100.0
1 2020-01-01 09:45:00  102.0
2 2020-01-01 10:05:00  101.0
3 2020-01-01 10:30:00  105.0
4 2020-01-01 10:55:00  103.0
5 2020-01-01 11:10:00  104.0

Output

                      open   high    low  close
time                                           
2020-01-01 09:00:00  100.0  102.0  100.0  102.0
2020-01-01 10:00:00  101.0  105.0  101.0  103.0
2020-01-01 11:00:00  104.0  104.0  104.0  104.0

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)