1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
window_rolling.go 906 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-02-14 08:08 . !59#I6F1P2优化序列处理方式
package stat
// RollingAndExpandingMixin 滚动和扩展静态横切
type RollingAndExpandingMixin struct {
Window []DType
Series Series
}
func (r RollingAndExpandingMixin) GetBlocks() (blocks []Series) {
for i := 0; i < r.Series.Len(); i++ {
N := r.Window[i]
if DTypeIsNaN(N) || int(N) > i+1 {
blocks = append(blocks, r.Series.Empty())
continue
}
window := int(N)
start := i + 1 - window
end := i + 1
blocks = append(blocks, r.Series.Subset(start, end, false))
}
return
}
// Apply 接受一个回调
func (r RollingAndExpandingMixin) Apply(f func(S Series, N DType) DType) (s Series) {
values := make([]DType, r.Series.Len())
for i, block := range r.GetBlocks() {
if block.Len() == 0 {
values[i] = DTypeNaN
continue
}
v := f(block, r.Window[i])
values[i] = v
}
s = r.Series.Empty(SERIES_TYPE_DTYPE)
s.Rename(r.Series.Name())
s = s.Append(values)
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.7.4

搜索帮助

344bd9b3 5694891 D2dac590 5694891