感謝@Sergey Bushmanov。它解決了我的問題。 並添加更多爲我的特殊情況。由於數據中存在一些時間差異,所以我不能直接使用resample。
我在上面的代碼中嘗試了這個基礎。結果很好。
df.reset_index(inplace=True)
groupby_list=list((df.index/15).map(lambda x:int(x)))
df.groupby(groupby_list).agg({
'code':'first','date':'first', 'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last'})
結果:
open high code close low date
0 3992.0 3992.0 jd1709 3916.0 3914.0 2017-04-10 09:01:00
1 3916.0 3935.0 jd1709 3920.0 3913.0 2017-04-10 09:16:00
2 3919.0 3926.0 jd1709 3921.0 3910.0 2017-04-10 09:31:00
3 3921.0 3923.0 jd1709 3920.0 3913.0 2017-04-10 09:46:00
4 3919.0 3928.0 jd1709 3927.0 3917.0 2017-04-10 10:01:00
5 3926.0 3932.0 jd1709 3927.0 3923.0 2017-04-10 10:31:00
6 3927.0 3928.0 jd1709 3915.0 3912.0 2017-04-10 10:46:00
7 3916.0 3924.0 jd1709 3918.0 3912.0 2017-04-10 11:01:00
8 3919.0 3925.0 jd1709 3916.0 3916.0 2017-04-10 11:16:00
9 3917.0 3928.0 jd1709 3924.0 3912.0 2017-04-10 13:31:00
你可以發佈你已經嘗試什麼,即使它是錯的? –
15行,你的意思是15分鐘?如果是這樣,那麼開放和高點會是什麼?最大/最小打開或第一次打開?同樣的問題關閉。 – pshep123