实现滚动和扩展等窗口操作。
项目描述
Window ops
这个库旨在用作替代`pd.Series.rolling`和`pd.Series.expanding`的选项,通过使用在numpy数组上操作的numba优化函数来提高速度。还有用于更高效更新窗口统计的在线类。
安装
pip安装window-ops
如何使用
转换
对于n_samples
-> n_samples
的转换,您可以在一个数组上使用[seasonal_](rolling|expanding)_(mean|max|min|std)
。
基准测试
pd.__version__
'1.3.5'
n_samples = 10_000 # array size
window_size = 8 # for rolling operations
season_length = 7 # for seasonal operations
execute_times = 10 # number of times each function will be executed
平均时间(毫秒)。
times.applymap('{:.2f}'.format)
window_ops | pandas | |
---|---|---|
rolling_mean | 0.03 | 0.43 |
rolling_max | 0.14 | 0.57 |
rolling_min | 0.14 | 0.58 |
rolling_std | 0.06 | 0.54 |
expanding_mean | 0.03 | 0.31 |
expanding_max | 0.05 | 0.76 |
expanding_min | 0.05 | 0.47 |
expanding_std | 0.09 | 0.41 |
seasonal_rolling_mean | 0.05 | 3.89 |
seasonal_rolling_max | 0.18 | 4.27 |
seasonal_rolling_min | 0.18 | 3.75 |
seasonal_rolling_std | 0.08 | 4.38 |
seasonal_expanding_mean | 0.04 | 3.18 |
seasonal_expanding_max | 0.06 | 3.29 |
seasonal_expanding_min | 0.06 | 3.28 |
seasonal_expanding_std | 0.12 | 3.89 |
speedups = times['pandas'] / times['window_ops']
speedups = speedups.to_frame('times faster')
speedups.applymap('{:.0f}'.format)
快77倍 | |
---|---|
rolling_mean | 15 |
rolling_max | 4 |
rolling_min | 4 |
rolling_std | 9 |
expanding_mean | 12 |
expanding_max | 15 |
expanding_min | 9 |
expanding_std | 4 |
seasonal_rolling_mean | 77 |
seasonal_rolling_max | 23 |
seasonal_rolling_min | 21 |
seasonal_rolling_std | 52 |
seasonal_expanding_mean | 78 |
seasonal_expanding_max | 52 |
seasonal_expanding_min | 51 |
seasonal_expanding_std | 33 |
在线
如果您有一个数组,您希望计算窗口统计并随着更多样本的输入而更新它,您可以使用`window_ops.online`模块中的类。它们都具有`fit_transform`方法,它接受数组并返回上面定义的转换,但还具有一个`update`方法,它接受单个值并返回新的统计值。
基准测试
转换数组和执行100次更新所需的时间(毫秒)。
times.to_frame().applymap('{:.2f}'.format)
平均时间(ms) | |
---|---|
RollingMean | 0.12 |
RollingMax | 0.23 |
RollingMin | 0.22 |
RollingStd | 0.32 |
ExpandingMean | 0.10 |
ExpandingMax | 0.07 |
ExpandingMin | 0.07 |
ExpandingStd | 0.17 |
SeasonalRollingMean | 0.28 |
SeasonalRollingMax | 0.35 |
季节滚动最小值 | 0.38 |
季节滚动标准差 | 0.42 |
季节扩展平均值 | 0.17 |
季节扩展最大值 | 0.14 |
季节扩展最小值 | 0.15 |
季节扩展标准差 | 0.23 |
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
window_ops-0.0.15.tar.gz (16.7 kB 查看哈希值)
构建分布
window_ops-0.0.15-py3-none-any.whl (15.4 kB 查看哈希值)
关闭
window_ops-0.0.15.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3c762d35a38d562f34cda33a272ced2c8d5dd88bd050c13bc82a592cf668a535 |
|
MD5 | d738acb1d97a9785a9a4bf3e8bbd5ecb |
|
BLAKE2b-256 | 39b6ef47c9fd20fba724304ffd3f7c4384c07a40b0cc6d41a617d63dd185af0c |
关闭
window_ops-0.0.15-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7dbd18b467939ac5db3f6834c07e7ffb723691f5d86c22a39e707713d8ac86e3 |
|
MD5 | 4da3838be59c0b710a618d878c274b14 |
|
BLAKE2b-256 | 5be5da17e2a457af1c37113d5aeb683d306e19ee15ed037a47dd7e78ebd07d88 |