[英]Get min values between hours for each day
I have a pandas time series dataframe with a value for each hour of the day over an extended period, like this: 我有一个熊猫时间序列数据帧,其中有一个长时间段中一天中每个小时的值,如下所示:
value
datetime
2018-01-01 00:00:00 38
2018-01-01 01:00:00 31
2018-01-01 02:00:00 78
2018-01-01 03:00:00 82
2018-01-01 04:00:00 83
2018-01-01 05:00:00 95
...
I want to create a new dataframe with the minimum value between hours 01:00 - 04:00 for each day but can't figure out how to do this.. the closest i can think of is: 我想创建一个新的数据框,且每天的小时数在01:00-04:00之间为最小值,但无法弄清楚该怎么做..我能想到的最接近的是:
df2 = df.groupby([pd.Grouper(freq='d'), df.between_time('01:00', '04:00')]).min()))
but that gives me: 但这给了我:
ValueError: Grouper for '' not 1-dimensional
ValueError:“不是”一维的石斑鱼
Use DataFrame.between_time
with DataFrame.resample
: 将
DataFrame.between_time
与DataFrame.resample
DataFrame.between_time
使用:
df = df.between_time('01:00', '04:00').resample('d').min()
print (df)
value
datetime
2018-01-01 31
Your solution is very close, only chain functions differently: 您的解决方案非常接近,只有链的功能不同:
df = df.between_time('01:00', '04:00').groupby(pd.Grouper(freq='d')).min()
print (df)
value
datetime
2018-01-01 31
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.