在计算移动平均线时,如何设置开始时间和结束时间?

2024-09-29 17:19:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从10秒的记录数据中计算15分钟、8小时和24小时的移动平均值。我应该如何设置开始时间和结束时间来计算移动平均线

我使用了以下代码来计算移动平均线

 Gas_432.set_index('RecTime').rolling(90).mean()
 Gas_432.between_time('2019-05-31 00:00:00','2019-07-04 08:08:21')

但我收到一条错误信息 TypeError: Index must be DatetimeIndex


Tags: 数据代码indextime记录时间betweenmean
1条回答
网友
1楼 · 发布于 2024-09-29 17:19:21

在创建DatetimeIndex之后使用^{}

#if not datetimes
Gas_432['RecTime'] = pd.to_datetime(Gas_432['RecTime'])

Gas_432 = (Gas_432.set_index('RecTime')
                  .truncate('2019-05-31 00:00:00','2019-07-04 08:08:21')
                  .rolling(90)
                  .mean())

相关问题 更多 >

    热门问题