如何对不规则的时间戳列表进行重新采样/降采样? [英] How to resample / downsample an irregular timestamp list?
本文介绍了如何对不规则的时间戳列表进行重新采样/降采样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个简单的问题,但我找不到一个简单的答案.
SImple question but I haven't been able to find a simple answer.
我有一个数据列表,该列表以秒为单位计算事件发生的时间:
I have a list of data which counts the time in seconds that events occur:
[200.0 420.0 560.0 1100.0 1900.0 2700.0 3400.0 3900.0 4234.2 4800.0 etc..]
我想统计每小时(3600秒)发生了多少事件,并为这些计数创建一个新列表.
I want to count how many events occur each hour (3600 seconds) and create a new list of these counts.
我知道这称为下采样,但是我能找到的所有信息都与传统时间序列有关.
I understand this is called downsampling, but all the information I can find is related to traditional time series.
对于上面的示例,新列表如下所示:
For the example above the new list would look like:
[7 3 etc..]
任何帮助将不胜感激.
推荐答案
all_events = [
200.0, 420.0, 560.0, 1100.0, 1900.0, 2700.0, 3400.0, 3900.0, 4234.2, 4800.0]
def get_events_by_hour(all_events):
return [
len([x for x in all_events if int(x/3600.0) == hour])
for hour in xrange(24)
]
print get_events_by_hour(all_events)
请注意,all_events应该包含一天的事件.
Note that all_events should contain events for one day.
这篇关于如何对不规则的时间戳列表进行重新采样/降采样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文