简体   繁体   English

Python:查找最小的每分钟时间戳数据帧

[英]Python: find minimum every minute timestamp dataframe

Hello I have the following data frame. 您好,我有以下数据框。 I would like to know if there is a systematic way to check the minimum value for instance every minute. 我想知道是否有系统的方法检查每分钟的最小值。 In particular giving the following: 特别是给出以下内容:

df 
ID    TIME          VAL
0   3/10/2014 8:02  6
1   3/10/2014 8:02  6.5
2   3/10/2014 8:04  7
3   3/10/2014 8:05  6.5
4   3/10/2014 8:05  6
5   3/10/2014 8:05  5.5
6   3/10/2014 8:06  5
7   3/10/2014 8:06  4.5
8   3/10/2014 8:08  4
9   3/10/2014 8:08  4.5
10  3/10/2014 8:09  5
11  3/10/2014 8:09  5.5
12  3/10/2014 8:09  6
13  3/10/2014 8:10  6.5
14  3/10/2014 8:10  7

I would like to have a column minimum that take the minimum val each minute 我想要一个minimum的列,每分钟取最小的val

ID    TIME          VAL MINIMUM
0   3/10/2014 8:02  6   6
1   3/10/2014 8:02  6.5 6
2   3/10/2014 8:04  7   7
3   3/10/2014 8:05  6.5 5.5
4   3/10/2014 8:05  6   5.5
5   3/10/2014 8:05  5.5 5.5
6   3/10/2014 8:06  5   4.5
7   3/10/2014 8:06  4.5 4.5
8   3/10/2014 8:08  4   4
9   3/10/2014 8:08  4.5 4
10  3/10/2014 8:09  5   5
11  3/10/2014 8:09  5.5 5
12  3/10/2014 8:09  6   5
13  3/10/2014 8:10  6.5 6.5
14  3/10/2014 8:10  7   6.5
grouped = df.groupby( (df["TIME"].dt.hour, df["TIME"].dt.minute) )
minimums = grouped.agg(numpy.min)

you will then need to figure out how to apply that list of minimums to your dataframe as a new column ... I will leave this as an exercise for you 然后,您将需要弄清楚如何将最小值列表应用到数据框中作为新列...我将把它作为练习留给您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM