简体   繁体   English

获取每天几小时之间的最小值

[英]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_timeDataFrame.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.

相关问题 获取每天之间的小时范围 - Get hour range between each day 在Python中获取最小值和最大值之间的值 - Get a value between min and max values in Python 获取每天数据框中的值的计数或总和 - Get count or sum of values in dataframe of each day R或Python-循环测试数据-未来24小时进行预测验证(每天96个值) - R or Python - loop the test data - Prediction validation next 24 hours (96 values each day) Python:如何在每天的温度值之间迭代以创建每天的 json 温度数组? - Python: How to iterate between temperature values of each day to create json temperature array for each day? Python:每天两个日期时间之间的小时数 - Python: Hours between two datetimes by day 在日志文件中查找每天的 min() 和 max() - Find min() and max() for each day in log file 我如何获得两个日期之间的差异,但也有一种方法可以总结每天的小时数? - How do I get difference between two dates but also have a way to sum up hours by day? Python 从秒中获取小时分钟和天数 - Python get hours min and days from the seconds 如果最小值满足条件,则获取二维np.array中每一行的最小值索引。 - Get the indices of min values for each row in a 2D np.array, if the min value satisfies a condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM