在 Pandas 中将每小时数据上采样到 5 分钟数据

编程入门 行业动态 更新时间:2024-10-12 01:21:32
本文介绍了在 Pandas 中将每小时数据上采样到 5 分钟数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下数据:

MTU (CET) Day-ahead Price [EUR/MWh] 0 09.10.2017 00:00 - 09.10.2017 01:00 43.13 1 09.10.2017 01:00 - 09.10.2017 02:00 34.80 2 09.10.2017 02:00 - 09.10.2017 03:00 33.31 3 09.10.2017 03:00 - 09.10.2017 04:00 32.24 ....... 22 09.10.2017 22:00 - 09.10.2017 23:00 49.06 23 09.10.2017 23:00 - 10.10.2017 00:00 38.46

我希望每 5 分钟获取一次数据.通过使用:

From which I would like to have data for every 5 minutes. By using:

price = pd.read_csv(price_data) price_x = price.set_index(pd.DatetimeIndex(price['MTU (CET)'].str[:-19])) price2 = price_x.resample('300S').pad()

我得到以下数据:

2017-09-10 00:00:00 43.13 2017-09-10 00:05:00 43.13 2017-09-10 00:10:00 43.13 ... 2017-09-10 22:45:00 49.06 2017-09-10 22:50:00 49.06 2017-09-10 22:55:00 49.06 2017-09-10 23:00:00 38.46

但是,对于 23:00 到 00:00 之间的分钟,价格也应该是 38.46.有人知道怎么帮忙吗?

However, for the minutes between 23:00 and 00:00 the price should also be 38.46. Does anyone know how to help?

推荐答案

您需要手动添加下一个小时的最后一行以及 iloc 选择的最后一行的数据:

You need manually add last row with next hour and with data from last row seelcted by iloc:

price_x = price.set_index(pd.DatetimeIndex(price['MTU (CET)'].str[:-19])) price_x.loc[price_x.index[-1] + pd.Timedelta(1, unit='h')] = price_x.iloc[-1] print (price_x.tail(3)) Day-ahead Price [EUR/MWh] MTU (CET) 2017-09-10 22:00:00 49.06 2017-09-10 23:00:00 38.46 2017-09-11 00:00:00 38.46

price2 = price_x.resample('300S').pad() print (price2.tail(20)) Day-ahead Price [EUR/MWh] MTU (CET) 2017-09-10 22:25:00 49.06 2017-09-10 22:30:00 49.06 2017-09-10 22:35:00 49.06 2017-09-10 22:40:00 49.06 2017-09-10 22:45:00 49.06 2017-09-10 22:50:00 49.06 2017-09-10 22:55:00 49.06 2017-09-10 23:00:00 38.46 2017-09-10 23:05:00 38.46 2017-09-10 23:10:00 38.46 2017-09-10 23:15:00 38.46 2017-09-10 23:20:00 38.46 2017-09-10 23:25:00 38.46 2017-09-10 23:30:00 38.46 2017-09-10 23:35:00 38.46 2017-09-10 23:40:00 38.46 2017-09-10 23:45:00 38.46 2017-09-10 23:50:00 38.46 2017-09-10 23:55:00 38.46 2017-09-11 00:00:00 38.46

更多推荐

在 Pandas 中将每小时数据上采样到 5 分钟数据

本文发布于:2023-10-18 17:28:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   每小时   中将   Pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!