如何重新采样此数据框?

斜纹

我正在尝试对即将到来的DF进行重新采样,以供以后制作滞后功能。

Mi_Meteo.head()


  Sensor ID   Time Instant    Measurement
0   14121   2013/11/14 17:00    0.8
1   14121   2013/11/14 18:00    0.6
2   14121   2013/11/14 19:00    0.4
3   14121   2013/11/14 20:00    0.4
4   14121   2013/11/14 21:00    0

所以,这就是我要做的:

Mi_Meteo = Mi_Meteo.set_index(['Time Instant']) # to Make The Time Instant as an Index

接着 :

Mi_Meteo.index = pd.to_datetime(Mi_Meteo.index) #  to convert it to a DateTimeIndex

但是我得到这个错误:

Unknown string format

知道我要获得这样的DF(时间范围为3H)

    Time Instant         Sensor ID          Measurement
0   2013/11/14 00:00:00    14121                0.8
1   2013/11/14 03:00:00    14121                0.6
2   2013/11/14 06:00:00    14121                0.4
3   2013/11/14 09:00:00    14121                0.4
4   2013/11/14 12:00:00    14121                 0

谢谢大家。

耶斯列尔

有一些不良数据,请NaNerrors='coerce'参数将其转换为s

Mi_Meteo.index = pd.to_datetime(Mi_Meteo.index, errors='coerce')

如果需要,请检查以下行:

print (Mi_Meteo[pd.to_datetime(Mi_Meteo.index, errors='coerce').isna()])

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章