gitee.com/quant1x/engine@v1.8.4/utils/series.go (about)

     1  package utils
     2  
     3  import (
     4  	"gitee.com/quant1x/num"
     5  	"gitee.com/quant1x/pandas"
     6  )
     7  
     8  func IndexReverse(s pandas.Series) pandas.Series {
     9  	var indexes []int
    10  	rows := s.Len()
    11  	s.Apply(func(idx int, v any) {
    12  		indexes = append(indexes, rows-idx)
    13  	})
    14  	return pandas.ToSeries(indexes...)
    15  }
    16  
    17  // SeriesIndexOf 获取序列第n索引的值
    18  //
    19  // Deprecated: 推荐使用 Float64IndexOf
    20  func SeriesIndexOf(s pandas.Series, n int) float64 {
    21  	v := s.IndexOf(n)
    22  	return num.AnyToFloat64(v)
    23  }
    24  
    25  // SeriesChangeRate 计算两个序列的净增长
    26  func SeriesChangeRate(base, v pandas.Series) pandas.Series {
    27  	chg := v.Div(base).Sub(1.00).Mul(100)
    28  	return chg
    29  }
    30  
    31  func StringIndexOf(s pandas.Series, n int) string {
    32  	v := s.IndexOf(n)
    33  	return num.AnyToString(v)
    34  }
    35  
    36  func BoolIndexOf(s pandas.Series, n int) bool {
    37  	v := s.IndexOf(n)
    38  	return num.AnyToBool(v)
    39  }
    40  
    41  func Float64IndexOf(s pandas.Series, n int) float64 {
    42  	v := s.IndexOf(n)
    43  	return num.AnyToFloat64(v)
    44  }
    45  
    46  func IntegerIndexOf(s pandas.Series, n int) int {
    47  	v := s.IndexOf(n)
    48  	return int(num.AnyToInt64(v))
    49  }
    50  
    51  func Int64IndexOf(s pandas.Series, n int) int64 {
    52  	v := s.IndexOf(n)
    53  	return num.AnyToInt64(v)
    54  }