1 Star 4 Fork 11

王布衣 / pandas

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
count.go 884 Bytes
Copy Edit Raw Blame History
package formula
import (
"gitee.com/quant1x/num"
"gitee.com/quant1x/pandas"
"reflect"
)
// COUNT 统计S为真的天数
func COUNT(S any, N any) pandas.Series {
ds := []bool{}
switch s := S.(type) {
case pandas.Series:
ds = s.Bools()
case []int8, []uint8, []int16, []uint16, []int32, []uint32, []int64, []uint64, []int, []uint, []uintptr, []float32, []float64, []bool, []string:
//sh := (*reflect.SliceHeader)(unsafe.Pointer(&S))
//fmt.Println(sh)
v := reflect.ValueOf(s)
length := v.Len()
ds = num.AnyToSlice[bool](s, length)
}
s := V1COUNT(ds, N)
return pandas.SliceToSeries(s)
}
// V1COUNT 统计S为真的天数
func V1COUNT(S []bool, N any) []int {
xLen := len(S)
x := num.Rolling(S, N)
ret := make([]int, xLen)
for i := 0; i < len(x); i++ {
n := 0
for _, v := range x[i] {
if num.AnyToBool(v) {
n++
}
}
ret[i] = n
}
return ret
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.4.1

Search

344bd9b3 5694891 D2dac590 5694891