在特定时间获取熊猫时间序列的价值 dict

让我说我有一个时间序列

2019-09-20 00:30:51.234260+00:00    4.63
2019-09-20 00:50:51.292892+00:00    4.40
2019-09-20 01:30:51.273058+00:00    4.54
2019-09-20 01:50:51.270876+00:00    4.44
2019-09-20 02:30:51.267385+00:00    4.55
                                    ... 
2019-10-30 22:57:35.003066+00:00    1.71
2019-10-30 23:12:34.965801+00:00    1.61
2019-10-30 23:27:34.976495+00:00    1.56
2019-10-30 23:42:34.984976+00:00    1.26
2019-10-30 23:57:34.965543+00:00    1.05

,我需要时间2019-09-20 00:40:00+00:00的值。假设这些值是根据值变化原理记录的,这意味着不需要插值,则正确答案为4.63。我该怎么办?

只需输入pandas_timeseries['2019-09-20 00:40:00+00:00']就会返回一个KeyError ...

我当时正在考虑将时间序列截断为after ='2019-09-20 00:40:00 + 00:00',然后获取最后一个值,但这似乎很简单。

wangfang74wf 回答:在特定时间获取熊猫时间序列的价值 dict

dict

将在保持排序的同时返回可以插入被搜索内容的位置。

我假设您的时间序列名称为searchsorted。我减去一个是因为您正在寻找职位。

s

否则,您可以将lookup = pd.Timestamp('2019-09-20 00:40:00+00:00') s.iloc[s.index.searchsorted(lookup) - 1] 4.63 reindex一起使用

ffill
本文链接:https://www.f2er.com/3150007.html

大家都在问