0
点赞
收藏
分享

微信扫一扫

python _滑动时间窗


python _滑动时间窗

一种用于时间序列操作的重要用法,是使用滑窗(sliding windown)或呈指数降低的权重(exponentially decaying weights),来对时间序列进行统计值计算和其他一些函数计算。 这个对于消除噪声或有缺陷的数据是很有用的
做平滑处理,削弱短期波动影响

# 滑动时间窗
import pandas as pd

# 模拟数据
time_index = pd.date_range("01/01/2010", periods=5, freq="M")

# 设置索引
dataframe = pd.DataFrame(index=time_index)

# 模拟数据
dataframe["Stock_Price"] = [1,2,3,4,5]
dataframe

Stock_Price
2010-01-31 1
2010-02-28 2
2010-03-31 3
2010-04-30 4
2010-05-31 5
# 计算滚动平均值
dataframe.rolling(window=2).mean()
Stock_Price
2010-01-31 NaN
2010-02-28 1.5
2010-03-31 2.5
2010-04-30 3.5
2010-05-31 4.5


举报

相关推荐

0 条评论