【问题标题】:How do you retrieve the min and max of time series data如何检索时间序列数据的最小值和最大值
【发布时间】:2017-10-09 04:44:22
【问题描述】:

我想使用 matplotlib 在我的时间序列数据的最小值和最大值之间进行遮蔽。这是数据示例。我如何检索最小值和最大值。 (请注意,下面给出的时间是字符串格式,但我的时间是从前一天 00:00:00 开始的秒数,所以我的时间是 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

【问题讨论】:

    标签: pandas numpy matplotlib time-series


    【解决方案1】:

    aggregaterename 一起使用:

    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:在 Series 上使用 dict 进行聚合 已弃用并将在未来版本中删除 df = df.groupby('time')['value'].agg({'min':'min_value','max':'max_value'})

    【讨论】:

      猜你喜欢
      • 2023-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      • 2012-04-03
      • 2011-01-27
      相关资源
      最近更新 更多