2 回答

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
你可以使用這個(gè):
df[df.index.strftime('%H:%M:%S') == '09:30:00']
輸出:
open high low close volume returns return_final
Datetime
2020-07-06 09:30:00 255.337982 261.950012 253.208786 261.421997 6592145 -6.084015 1
2020-07-07 09:30:00 281.002014 285.641998 267.341980 277.621979 10130111 3.380035 -1
一天中的多個(gè)時(shí)間:
df[df.index.strftime('%H:%M:%S').isin(['09:30:00','11:00:00'])]
您可以使用過(guò)濾器,就像使用正則表達(dá)式一樣:
df.filter(regex='09:30|11:00', axis=0)
輸出:
open high low close volume returns return_final
Datetime
2020-07-06 09:30:00 255.337982 261.950012 253.208786 261.421997 6592145 -6.084015 1.000000 NaN NaN
2020-07-06 11:00:00 261.526001 268.399994 261.239990 266.275452 4955678 -4.749451 1.000000 NaN NaN
2020-07-07 09:30:00 281.002014 285.641998 267.341980 277.621979 10130111 3.380035 -1.0 NaN
2020-07-07 11:00:00 278.000000 284.600006 276.536011 278.123718 4221461 -0.123718 1.000000 NaN NaN

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
看起來(lái)好像有效。
df.filter(like='09:30', axis=0)
open high low close volume returns returns_final
Datetime
2020-07-06 09:30:00 255.337982 261.950012 253.208786 261.421997 6592145 -6.084015 1
2020-07-07 09:30:00 281.002014 285.641998 267.341980 277.621979 10130111 3.380035 -1
2020-07-08 09:30:00 281.000000 283.399994 277.662018 278.865784 4698944 2.134216 -1
2020-07-09 09:30:00 279.398010 281.500000 271.919983 272.015991 4562064 7.382019 -1
2020-07-10 09:30:00 278.220367 283.799988 275.202026 283.506012 4274774 -5.285645 1
添加回答
舉報(bào)