我需要把记录(传感器数据)记录在熊猫.数据帧但我只需要保留最后24小时。每秒钟都会有一个新记录出现。在
记录格式为:
{'Date': ..., 'Sensor1': 10, 'Sensor2': 12, ...}
其中'Date'也应该是数据帧的索引。在
当然,也可以使用:
df = df.append( newRecord )
df.drop( df[df.Date < datetime.now() - timedelta( hours=24 )].index] )
但我觉得很难看。在
什么是最有效和熊猫式的方法?在
Tags:
我认为您可以使用
^{pr2}$subset
和{a1}来删除行,但这不是最快的方法。您可以将列Date
设置为index
,然后按时间end
剪切DataFrame
。在测试:
每秒钟都要删除重新组织所有数据帧,这是一项代价高昂的操作:
通过固定的滚动缓冲器可以避免这种情况,从而有效地存储传感器数据。索引只是一个整数,一天中每秒一个。在
^{pr2}$这样添加样本的速度非常快:
要将电流倒流24小时,只需执行以下操作:
现在时间就是索引。在
相关问题 更多 >
编程相关推荐