如何修复这个不正确的重采样?
How to Fix This Incorrect Resampling?
我正在尝试对即将发布的 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, errors='coerce') # to convert it to a DateTimeIndex
Mi_Meteo.resample('3H') # to get a temporal range of 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
我得到相同的 DF,但现在 'Time Instant ' 是索引 :
Time Instant Sensor ID Measurement
0 2013/11/14 17:00 14121 0.8
1 2013/11/14 18:00 14121 0.6
2 2013/11/14 19:00 14121 0.4
3 2013/11/14 20:00 14121 0.4
4 2013/11/14 21:00 14121 0
有什么建议吗? , 谢谢你
符合预期,在聚合函数后添加DataFrame.reset_index
:
df = Mi_Meteo.resample('3H').sum().reset_index()
我正在尝试对即将发布的 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, errors='coerce') # to convert it to a DateTimeIndex
Mi_Meteo.resample('3H') # to get a temporal range of 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
我得到相同的 DF,但现在 'Time Instant ' 是索引 :
Time Instant Sensor ID Measurement
0 2013/11/14 17:00 14121 0.8
1 2013/11/14 18:00 14121 0.6
2 2013/11/14 19:00 14121 0.4
3 2013/11/14 20:00 14121 0.4
4 2013/11/14 21:00 14121 0
有什么建议吗? , 谢谢你
符合预期,在聚合函数后添加DataFrame.reset_index
:
df = Mi_Meteo.resample('3H').sum().reset_index()