1 Star 0 Fork 12

younland/pandas

forked from 王布衣/pandas 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dataframe_group.go 740 Bytes
一键复制 编辑 原始数据 按行查看 历史
package pandas
import (
"gitee.com/quant1x/gox/api"
"gitee.com/quant1x/pandas/stat"
)
// Group 分组
func (self DataFrame) Group(columnName string, filter func(kind stat.Type, e any) bool) DataFrame {
return self.Filter(columnName, filter)
}
// Filter 过滤
func (self DataFrame) Filter(columnName string, filter func(kind stat.Type, e any) bool) DataFrame {
series := self.Col(columnName)
if series.Len() == 0 {
return self
}
t := series.Type()
indexes := []int{}
series.Apply(func(idx int, v any) {
ok := filter(t, v)
if ok {
indexes = append(indexes, idx)
}
})
ranges := api.IntsToRanges(indexes)
df := DataFrame{}
for _, r := range ranges {
tmp := self.SelectRows(r)
df = df.Concat(tmp)
}
return df
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/younland/pandas.git
git@gitee.com:younland/pandas.git
younland
pandas
pandas
master

搜索帮助