1 Star 4 Fork 10

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dataframe_group.go 696 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-02-18 15:25 . dataframe适配series
package pandas
import (
"gitee.com/quant1x/gox/api"
)
// Group 分组
func (this DataFrame) Group(columnName string, filter func(kind Type, e any) bool) DataFrame {
return this.Filter(columnName, filter)
}
// Filter 过滤
func (this DataFrame) Filter(columnName string, filter func(kind Type, e any) bool) DataFrame {
series := this.Col(columnName)
if series.Len() == 0 {
return this
}
t := series.Type()
var 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 := this.SelectRows(r)
df = df.Concat(tmp)
}
return df
}
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.4.7

搜索帮助