开发者

How to use the resampling function to create 23 hour average data

I want to make an average every 23 hours from 10:00 a.m to 9:00 a.m. the next day. but i can't find solution

newDf = Data_s.resample(rule='H').mean()

I think I can change this code, but I don't know how. My data are divided from March 11th to April 10th, 23. like that 2022-03-11 00:00 2022-03-11 00:01 .... 2022-04-11 00:00

I would appreciate it if you could let me know if there is a way

thank you

i try like that

newDf = Data_s.resample(rule='23H',origin=).mean()

but It only makes an average for 23开发者_开发百科 hours in a row. and other simple method is delete data (just 8 a.m) but i want to know how can make it by code thank you.


Since "every 23 hours from 10:00 a.m to 9:00 a.m" means exluding the '9th hour', here's one possible way to do it:

import pandas as pd

df = pd.DataFrame({
    "time": pd.date_range(start="2022-03-11 00:00", end="2022-04-11 00:00", freq="min"),
    "value": 1
})

hour_to_exclude = 9
time_subset = df[df["time"].dt.hour != hour_to_exclude]
time_subset.resample("D", on="time").mean()

Output:

            value
      time  
2022-03-11  1.0
2022-03-12  1.0
2022-03-13  1.0
2022-03-14  1.0
2022-03-15  1.0
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜