如何设置计算移动平均线的开始时间和结束时间?
How to set the start time and end time in calculating moving averages?
我正在尝试根据 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
创建DatetimeIndex
后使用DataFrame.truncate
:
#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())
我正在尝试根据 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
创建DatetimeIndex
后使用DataFrame.truncate
:
#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())