2 回答
TA贡献2065条经验 获得超13个赞
你可以使用这个:
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
一天中的多个时间:
df[df.index.strftime('%H:%M:%S').isin(['09:30:00','11:00:00'])]
您可以使用过滤器,就像使用正则表达式一样:
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贡献1772条经验 获得超8个赞
看起来好像有效。
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
添加回答
举报