搜索缺少的时间戳并显示在python中? [英] Search Missing Timestamp and display in python?

查看:71
本文介绍了搜索缺少的时间戳并显示在python中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的一些具有时间,温度1,温度2的数据集

Here is my some Dataset which having Time,Temperature1,Temperature2

Timestamp.             Temperature1.        Temperature2
09/01/2016 00:00:08          53.4.                       45.5
09/01/2016 00:00:38.         53.5.                       45.2
09/01/2016 00:01:08.         54.6.                        43.2
09/01/2016 00:01:38.         55.2.                        46.3
09/01/2016 00:02:08.         54.5.                        45.5
09/01/2016 00:04:08.         54.2.                       35.5
09/01/2016 00:05:08.         52.4.                        45.7
09/01/2016 00:05:38.         53.4.                         45.2

我的数据每30秒发送一次.

My data is coming in every 30 second..

这是我的数据集..缺少一些时间戳..bcoz.每隔30秒我的数据就会来..所以一些数据点丢失了. 如何找到该数据点..并将其中的数据作为NAN插入... 请帮助我.

This is my dataset here..some Timestamp is missing..bcoz. every 30 second my data is coming..so some data points are missing.. How to find that data points..and insert there data as NAN ... Please help me..

推荐答案

,您可以使用上面的解决方案假定Timestampdatetime dtype,并且已将其设置为索引. 如果Timestamp是常规列(不是索引),那么从Pandas 0.19.0开始,我们可以使用on='column_name'参数在常规列(必须为datetime dtype)上重新采样:

The solution above assumes that the Timestamp is of datetime dtype and that it has been set as index. If Timestamp is a regular column (not index), then starting from Pandas 0.19.0 we can resample on regular columns (it must be of datetime dtype), using on='column_name' parameter:

In [26]: x.resample('30S', on='Timestamp', base=8).mean()
Out[26]:
                                 Temperature1    Temperature2
Timestamp
2016-09-01 00:00:08                      53.4            45.5
2016-09-01 00:00:38                      53.5            45.2
2016-09-01 00:01:08                      54.6            43.2
2016-09-01 00:01:38                      55.2            46.3
2016-09-01 00:02:08                      54.5            45.5
2016-09-01 00:02:38                       NaN             NaN
2016-09-01 00:03:08                       NaN             NaN
2016-09-01 00:03:38                       NaN             NaN
2016-09-01 00:04:08                      54.2            35.5
2016-09-01 00:04:38                       NaN             NaN
2016-09-01 00:05:08                      52.4            45.7
2016-09-01 00:05:38                      53.4            45.2

如果您需要动态找到您的base值,您可以通过以下方式做到这一点:

if you need to find your base value dynamically you can do it this way:

In [21]: x.index[0].second
Out[21]: 8

来自 docs :

基本:整数,默认为0

base : int, default 0

对于平均细分为1天的频率,是汇总间隔的起点".例如,对于5min频率,基数范围可以从04.

For frequencies that evenly subdivide 1 day, the "origin" of the aggregated intervals. For example, for 5min frequency, base could range from 0 through 4.

默认为0

这篇关于搜索缺少的时间戳并显示在python中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆