gpt4 book ai didi

python - pandas.DataFrame.last 给出整个数据帧而不是它的一部分(python)

转载 作者:行者123 更新时间:2023-12-03 21:57:20 25 4
gpt4 key购买 nike

我在 5 小时数据(每分钟 300 行)的数据帧中使用 history.DataFrame.last('10s) 并给我整个数据帧。

另一方面,命令 history.between_time('22:06:00','22:10:00') 给了我正确的部分。

你可能知道是什么问题吗?谢谢你。

完整的数据框和结果如下:

    history = 

time low high open close volume
Index
2020-04-18 22:14:00 1587248040 170.27 170.32 170.27 170.32 32.788304
2020-04-18 22:13:00 1587247980 170.20 170.27 170.27 170.20 2.495578
2020-04-18 22:12:00 1587247920 170.20 170.27 170.20 170.27 28.454885
2020-04-18 22:11:00 1587247860 170.10 170.21 170.10 170.21 97.663555
2020-04-18 22:10:00 1587247800 169.80 170.10 169.84 169.94 189.118185
... ... ... ... ... ...
2020-04-18 17:15:00 1587230100 167.56 167.73 167.56 167.72 15.257272
2020-04-18 17:14:00 1587230040 167.63 167.72 167.67 167.72 0.405094
2020-04-18 17:13:00 1587229980 167.57 167.61 167.57 167.61 23.075999
2020-04-18 17:12:00 1587229920 167.49 167.61 167.61 167.60 9.606858
2020-04-18 17:11:00 1587229860 167.60 167.73 167.60 167.60 53.414672

[300 rows x 6 columns]

history.last('10s')
Out[84]:
time low high open close volume
Index
2020-04-18 22:14:00 1587248040 170.27 170.32 170.27 170.32 32.788304
2020-04-18 22:13:00 1587247980 170.20 170.27 170.27 170.20 2.495578
2020-04-18 22:12:00 1587247920 170.20 170.27 170.20 170.27 28.454885
2020-04-18 22:11:00 1587247860 170.10 170.21 170.10 170.21 97.663555
2020-04-18 22:10:00 1587247800 169.80 170.10 169.84 169.94 189.118185
... ... ... ... ... ...
2020-04-18 17:15:00 1587230100 167.56 167.73 167.56 167.72 15.257272
2020-04-18 17:14:00 1587230040 167.63 167.72 167.67 167.72 0.405094
2020-04-18 17:13:00 1587229980 167.57 167.61 167.57 167.61 23.075999
2020-04-18 17:12:00 1587229920 167.49 167.61 167.61 167.60 9.606858
2020-04-18 17:11:00 1587229860 167.60 167.73 167.60 167.60 53.414672

[300 rows x 6 columns]

history.between_time('22:06:00','22:10:00')
Out[82]:
time low high open close volume
Index
2020-04-18 22:10:00 1587247800 169.80 170.10 169.84 169.94 189.118185
2020-04-18 22:09:00 1587247740 169.90 169.97 169.90 169.97 11.503376
2020-04-18 22:08:00 1587247680 169.65 169.90 169.65 169.90 103.496717
2020-04-18 22:07:00 1587247620 169.63 169.65 169.65 169.63 2.708217
2020-04-18 22:06:00 1587247560 169.65 169.68 169.68 169.65 6.306080

最佳答案

您的索引需要按升序排序。

history.sort_index().last('10s')                                                                                                                                                                                                    
# time low high open close volume
# Index
# 2020-04-18 22:14:00 1587248040 170.27 170.32 170.27 170.32 32.788304

您的索引现在似乎已反转。所以没有 sort_index() ,实际上最后一行的索引时间最短。所有其他时间都在那之后,而 last()正在寻找删除引用时间前 10 秒以上的内容。

关于python - pandas.DataFrame.last 给出整个数据帧而不是它的一部分(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61297220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com