如何检索时间序列数据的最小值和最大值 [英] How do you retrieve the min and max of time series data
问题描述
我想使用matplotlib在时间序列数据的最小值和最大值之间进行着色.这是数据样本.我如何检索最小和最大. (请注意,下面给出的时间为字符串格式,但是我有前一天00:00:00起的秒数,因此我的时间为5902761,5902770)
I want to use matplotlib to shade between the minimum and maximum values of my timeseries data. Here is a sample of the data. How do i retrieve the min and max. (note that time given below is in string format but i have the time in seconds from previous day 00:00:00 so i have time as 5902761,5902770)
例如
index time value
1 08:00:00 100
2 08:00:01 100
3 08:00:01 101
4 08:00:02 100
5 08:00:02 102
6 08:00:02 101
我想要的是以下
index time min_value max_value
1 08:00:00 100 100
2 08:00:01 100 101
3 08:00:02 100 102
推荐答案
使用 aggregate
与rename
:
d = {'min':'min_value','max':'max_value'}
df = df.groupby('time')['value'].agg([min, max]).reset_index().rename(columns=d)
print (df)
time min_value max_value
0 08:00:00 100 100
1 08:00:01 100 101
2 08:00:02 100 102
因为:
df = df.groupby('time')['value'].agg({'min_value':'min','max_value':'max'})
FutureWarning:对系列使用dict进行汇总 已不推荐使用,并将在以后的版本中删除 df = df.groupby('time')['value'].agg({'min':'min_value','max':'max_value'})
FutureWarning: using a dict on a Series for aggregation is deprecated and will be removed in a future version df = df.groupby('time')['value'].agg({'min':'min_value','max':'max_value'})
这篇关于如何检索时间序列数据的最小值和最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!