Documentation
¶
Index ¶
- Constants
- Variables
- func ToBool(s Series) []bool
- func ToFloat32(s Series) []float32
- func ToFloat64(s Series) []float64
- type AlphaType
- type DataFrame
- func (this DataFrame) Col(colname string, args ...bool) Series
- func (this DataFrame) ColAsNDArray(colname string) Series
- func (this DataFrame) Concat(dfb DataFrame) DataFrame
- func (this DataFrame) Dims() (int, int)
- func (this DataFrame) Error() error
- func (this DataFrame) FillNa(v any, inplace bool)
- func (this DataFrame) Filter(columnName string, filter func(kind Type, e any) bool) DataFrame
- func (this DataFrame) Group(columnName string, filter func(kind Type, e any) bool) DataFrame
- func (this DataFrame) IndexOf(idx int, opt ...any) map[string]any
- func (this DataFrame) Join(S ...Series) DataFrame
- func (this DataFrame) Names() []string
- func (this DataFrame) Ncol() int
- func (this DataFrame) Nrow() int
- func (this DataFrame) Records(round ...bool) [][]string
- func (this DataFrame) Remove(p api.ScopeLimit) DataFrame
- func (this DataFrame) Select(indexes SelectIndexes) DataFrame
- func (this DataFrame) SelectRows(p api.ScopeLimit) DataFrame
- func (this DataFrame) SetName(from string, to string)
- func (this DataFrame) SetNames(colNames ...string) error
- func (this DataFrame) String() (str string)
- func (this DataFrame) Sub(start, end int) DataFrame
- func (this DataFrame) Subset(start, end int) DataFrame
- func (this DataFrame) Types() []string
- func (this DataFrame) WriteCSV(out any, options ...WriteOption) error
- type EW
- type ExponentialMovingWindow
- type LoadOption
- func DefaultType(t Type) LoadOption
- func DetectTypes(b bool) LoadOption
- func HasHeader(b bool) LoadOption
- func NaNValues(nanValues []string) LoadOption
- func Names(names ...string) LoadOption
- func WithComments(b rune) LoadOption
- func WithDelimiter(b rune) LoadOption
- func WithLazyQuotes(b bool) LoadOption
- func WithTypes(coltypes map[string]Type) LoadOption
- type NDFrame
- func (this *NDFrame) Add(x any) Series
- func (this *NDFrame) And(x any) Series
- func (this *NDFrame) Append(values ...any) Series
- func (this *NDFrame) Apply(f func(idx int, v any))
- func (this *NDFrame) Apply2(f func(idx int, v any) any, inplace ...bool) Series
- func (this *NDFrame) ArgMax() int
- func (this *NDFrame) ArgMin() int
- func (this *NDFrame) Bools() []bool
- func (this *NDFrame) Concat(x Series) Series
- func (this *NDFrame) Copy() Series
- func (this *NDFrame) DTypes() []num.DType
- func (this *NDFrame) Diff(param any) (s Series)
- func (this *NDFrame) Div(x any) Series
- func (this *NDFrame) EWM(alpha EW) ExponentialMovingWindow
- func (this *NDFrame) Empty(t ...Type) Series
- func (this *NDFrame) Eq(x any) Series
- func (this *NDFrame) FillNa(x any, inplace bool) Series
- func (this *NDFrame) Float32s() []float32
- func (this *NDFrame) Float64s() []float64
- func (this *NDFrame) Gt(x any) Series
- func (this *NDFrame) Gte(x any) Series
- func (this *NDFrame) IndexOf(index int, opt ...any) any
- func (this *NDFrame) Int32s() []int32
- func (this *NDFrame) Int64s() []int64
- func (this *NDFrame) Ints() []int
- func (this *NDFrame) Len() int
- func (this *NDFrame) Less(i, j int) bool
- func (this *NDFrame) Logic(f func(idx int, v any) bool) []bool
- func (this *NDFrame) Lt(x any) Series
- func (this *NDFrame) Lte(x any) Series
- func (this *NDFrame) Max() any
- func (this *NDFrame) Mean() num.DType
- func (this *NDFrame) Min() any
- func (this *NDFrame) Mul(x any) Series
- func (this *NDFrame) NaN() any
- func (this *NDFrame) Name() string
- func (this *NDFrame) Neq(x any) Series
- func (this *NDFrame) Not() Series
- func (this *NDFrame) Or(x any) Series
- func (this *NDFrame) Records(round ...bool) []string
- func (this *NDFrame) Ref(periods any) (s Series)
- func (this *NDFrame) Rename(name string)
- func (this *NDFrame) Repeat(x any, repeats int) Series
- func (this *NDFrame) Reverse() Series
- func (this *NDFrame) Rolling(param any) RollingAndExpandingMixin
- func (this *NDFrame) Select(r api.ScopeLimit) Series
- func (this *NDFrame) Set(index int, v any)
- func (this *NDFrame) Shift(periods int) Series
- func (this *NDFrame) Std() num.DType
- func (this *NDFrame) StdDev() num.DType
- func (this *NDFrame) String() string
- func (this *NDFrame) Strings() []string
- func (this *NDFrame) Sub(x any) Series
- func (this *NDFrame) Subset(start, end int, opt ...any) Series
- func (this *NDFrame) Sum() num.DType
- func (this *NDFrame) Swap(i, j int)
- func (this *NDFrame) Type() Type
- func (this *NDFrame) Values() any
- type RollingAndExpandingMixin
- func (r RollingAndExpandingMixin) Aggregation(f func(S Series) any) Series
- func (r RollingAndExpandingMixin) Apply(f func(S Series, N num.DType) num.DType) (s Series)
- func (r RollingAndExpandingMixin) Count() Series
- func (r RollingAndExpandingMixin) GetBlocks() (blocks []Series)
- func (r RollingAndExpandingMixin) Max() Series
- func (r RollingAndExpandingMixin) Mean() (s Series)
- func (r RollingAndExpandingMixin) Min() Series
- func (r RollingAndExpandingMixin) Std() Series
- func (r RollingAndExpandingMixin) Sum() Series
- type ScalarAggregation
- type SelectIndexes
- type Series
- func Align2Series(x any, N int) Series
- func Convect[T num.BaseType, F num.BaseType](data []F) Series
- func NewSeries[T num.BaseType](values ...T) Series
- func NewSeriesWithType(typ Type, name string, values ...any) Series
- func NewSeriesWithoutType(name string, values ...any) Series
- func SeriesWithName[T num.BaseType](name string, values []T) Series
- func SeriesWithoutName[E num.BaseType](values ...E) Series
- func SliceToSeries[E num.BaseType](data []E) Series
- func ToSeries[T num.BaseType](data ...T) Series
- func ToVector[E num.BaseType](data ...E) Series
- func Vector[E num.BaseType](data []E) Series
- type Type
- type WriteOption
Examples ¶
Constants ¶
const ( SERIES_TYPE_INVAILD = reflect.Invalid // 无效类型 SERIES_TYPE_BOOL = reflect.Bool // 布尔类型 SERIES_TYPE_INT32 = reflect.Int32 // int64 SERIES_TYPE_INT64 = reflect.Int64 // int64 SERIES_TYPE_FLOAT32 = reflect.Float32 // float32 SERIES_TYPE_FLOAT64 = reflect.Float64 // float64 SERIES_TYPE_STRING = reflect.String // string SERIES_TYPE_DTYPE = SERIES_TYPE_FLOAT64 // link float64 )
Supported Series Types
const ( //MAX_FLOAT32_PRICE = float32(9999.9999) // float32的价最大阀值触发扩展到float64 MAX_FLOAT32_PRICE = float32(0) // float32的价最大阀值触发扩展到float64 )
Variables ¶
var ( ErrUnsupportedType = errors.New("unsupported type") ErrCouldNotDetectType = errors.New("couldn't detect type") )
var (
DefaultTagName = api.DefaultTagName
)
Functions ¶
Types ¶
type AlphaType ¶
type AlphaType int
const ( // AlphaAlpha Specify smoothing factor α directly, 0<α≤1. AlphaAlpha AlphaType = iota // AlphaCom Specify decay in terms of center of mass, α=1/(1+com), for com ≥ 0. AlphaCom // AlphaSpan Specify decay in terms of span, α=2/(span+1), for span ≥ 1. AlphaSpan // AlphaHalfLife Specify decay in terms of half-life, α=1−exp(−ln(2)/halflife), for halflife > 0. AlphaHalfLife )
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.ewm.html
type DataFrame ¶
type DataFrame struct {
// deprecated: Use Error() instead
Err error
// contains filtered or unexported fields
}
DataFrame 以gota的DataFrame的方法为主, 兼顾新流程, 避免单元格元素结构化
func LoadMaps ¶
func LoadMaps(maps []map[string]any, options ...LoadOption) DataFrame
LoadMaps creates a new DataFrame based on the given maps. This function assumes that every map on the array represents a row of observations.
func LoadRecords ¶
func LoadRecords(records [][]string, options ...LoadOption) DataFrame
LoadRecords creates a new DataFrame based on the given records. 这个方法是从本地缓存文件读取数据的第二步, 数据从形式上只能是字符串
func LoadStructs ¶
func LoadStructs(i any, options ...LoadOption) DataFrame
LoadStructs creates a new DataFrame from arbitrary struct slices.
LoadStructs will ignore unexported fields inside an struct. Note also that unless otherwise specified the column names will correspond with the name of the field.
You can configure each field with the `dataframe:"name[,type]"` struct tag. If the name on the tag is the empty string `""` the field name will be used instead. If the name is `"-"` the field will be ignored.
Examples:
// field will be ignored field int // Field will be ignored Field int `dataframe:"-"` // Field will be parsed with column name Field and type int Field int // Field will be parsed with column name `field_column` and type int. Field int `dataframe:"field_column"` // Field will be parsed with column name `field` and type string. Field int `dataframe:"field,string"` // Field will be parsed with column name `Field` and type string. Field int `dataframe:",string"`
If the struct tags and the given LoadOptions contradict each other, the later will have preference over the former.
func NewDataFrame ¶
NewDataFrame is the generic DataFrame constructor
func ReadCSV ¶
func ReadCSV(in any, options ...LoadOption) DataFrame
ReadCSV reads a CSV file from a io.Reader and builds a DataFrame with the
resulting records. 支持文件名和io两种方式读取数据
func (DataFrame) Col ¶
Col returns a copy of the Series with the given column name contained in the DataFrame.
选取一列, Col方法的目的是保持现有的name等字段
func (DataFrame) Remove ¶
func (this DataFrame) Remove(p api.ScopeLimit) DataFrame
Remove 删除一段范围内的记录
func (DataFrame) Select ¶
func (this DataFrame) Select(indexes SelectIndexes) DataFrame
Select the given DataFrame columns
func (DataFrame) SelectRows ¶
func (this DataFrame) SelectRows(p api.ScopeLimit) DataFrame
SelectRows 选择一段记录
func (DataFrame) SetNames ¶
SetNames changes the column names of a DataFrame to the ones passed as an argument. 修改全部的列名
func (DataFrame) Subset ¶
Subset returns a subset of the rows of the original DataFrame based on the Series subsetting indexes.
type EW ¶
type EW struct {
Com num.DType // 根据质心指定衰减
Span num.DType // 根据跨度指定衰减
HalfLife num.DType // 根据半衰期指定衰减
Alpha num.DType // 直接指定的平滑因子α
Adjust bool // 除以期初的衰减调整系数以核算 相对权重的不平衡(将 EWMA 视为移动平均线)
IgnoreNA bool // 计算权重时忽略缺失值
Callback func(idx int) num.DType
}
EW (Factor) 指数加权(EW)计算Alpha 结构属性非0即为有效启动同名算法
type ExponentialMovingWindow ¶
type ExponentialMovingWindow struct {
Data Series // 序列
AType AlphaType // 计算方式: com/span/halflefe/alpha
Param num.DType // 参数类型为浮点
Adjust bool // 默认为真, 是否调整, 默认真时, 计算序列的EW移动平均线, 为假时, 计算指数加权递归
IgnoreNA bool // 默认为假, 计算权重时是否忽略缺失值NaN
Cb func(idx int) num.DType
// contains filtered or unexported fields
}
ExponentialMovingWindow 加权移动窗口
func (ExponentialMovingWindow) Mean ¶
func (w ExponentialMovingWindow) Mean() Series
type LoadOption ¶
type LoadOption func(*loadOptions)
LoadOption is the type used to configure the load of elements
func DefaultType ¶
func DefaultType(t Type) LoadOption
DefaultType sets the defaultType option for loadOptions.
func DetectTypes ¶
func DetectTypes(b bool) LoadOption
DetectTypes sets the detectTypes option for loadOptions.
func HasHeader ¶
func HasHeader(b bool) LoadOption
HasHeader sets the hasHeader option for loadOptions.
func NaNValues ¶
func NaNValues(nanValues []string) LoadOption
NaNValues sets the nanValues option for loadOptions.
func WithComments ¶
func WithComments(b rune) LoadOption
WithComments sets the csv comment line detect to remove lines
func WithDelimiter ¶
func WithDelimiter(b rune) LoadOption
WithDelimiter sets the csv delimiter other than ',', for example '\t'
func WithLazyQuotes ¶
func WithLazyQuotes(b bool) LoadOption
WithLazyQuotes sets csv parsing option to LazyQuotes
func WithTypes ¶
func WithTypes(coltypes map[string]Type) LoadOption
WithTypes sets the types option for loadOptions.
type NDFrame ¶
type NDFrame struct {
// contains filtered or unexported fields
}
NDFrame series多属性封装实现
func (*NDFrame) EWM ¶
func (this *NDFrame) EWM(alpha EW) ExponentialMovingWindow
func (*NDFrame) Rolling ¶
func (this *NDFrame) Rolling(param any) RollingAndExpandingMixin
type RollingAndExpandingMixin ¶
RollingAndExpandingMixin 滚动和扩展静态横切
func (RollingAndExpandingMixin) Aggregation ¶
func (r RollingAndExpandingMixin) Aggregation(f func(S Series) any) Series
Aggregation 接受一个聚合回调
func (RollingAndExpandingMixin) Count ¶
func (r RollingAndExpandingMixin) Count() Series
func (RollingAndExpandingMixin) GetBlocks ¶
func (r RollingAndExpandingMixin) GetBlocks() (blocks []Series)
func (RollingAndExpandingMixin) Mean ¶
func (r RollingAndExpandingMixin) Mean() (s Series)
Mean returns the rolling mean.
func (RollingAndExpandingMixin) Std ¶
func (r RollingAndExpandingMixin) Std() Series
func (RollingAndExpandingMixin) Sum ¶
func (r RollingAndExpandingMixin) Sum() Series
type ScalarAggregation ¶
type ScalarAggregation interface {
// Mean calculates the average value of a series
Mean() num.DType
// StdDev calculates the standard deviation of a series
StdDev() num.DType
// Max 找出最大值
Max() any
// ArgMax Returns the indices of the maximum values along an axis
ArgMax() int
// Min 找出最小值
Min() any
// ArgMin Returns the indices of the minimum values along an axis
ArgMin() int
// Diff 元素的第一个离散差
Diff(param any) (s Series)
// Std 计算标准差
Std() num.DType
// Sum 计算累和
Sum() num.DType
// Add 加
Add(x any) Series
// Sub 减
Sub(x any) Series
// Mul 乘
Mul(x any) Series
// Div 除
Div(x any) Series
// Eq 等于
Eq(x any) Series
// Neq 不等于
Neq(x any) Series
// Gt 大于
Gt(x any) Series
// Gte 大于等于
Gte(x any) Series
// Lt 小于
Lt(x any) Series
// Lte 小于等于
Lte(x any) Series
// And 与
And(x any) Series
// Or 或
Or(x any) Series
// Not 非
Not() Series
}
ScalarAggregation 标量聚合接口
type SelectIndexes ¶
type SelectIndexes any
SelectIndexes are the supported indexes used for the DataFrame.Select method. Currently supported are:
int // Matches the given index number []int // Matches all given index numbers []bool // Matches all columns marked as true string // Matches the column with the matching column name []string // Matches all columns with the matching column names Series [Int] // Same as []int Series [Bool] // Same as []bool Series [String] // Same as []string
type Series ¶
type Series interface {
String() string
// Name 取得series名称
Name() string
// Rename renames the series.
Rename(name string)
// Type returns the type of Data the series holds.
// 返回series的数据类型
Type() Type
// Values 获得全部数据集
Values() any
// NaN 输出默认的NaN
NaN() any
// DTypes 强制转[]num.DType
DTypes() []num.DType
// Float32s 强制转成[]float32
Float32s() []float32
// Float64s 强制转成[]float64
Float64s() []float64
// Ints 强制转换成[]int
Ints() []int
// Int32s 强制转换成[]int32
Int32s() []int32
// Int64s 强制转换成[]int64
Int64s() []int64
// Strings 强制转换string切片
Strings() []string
// Bools 强制转换成bool切片
Bools() []bool
// Len 获得行数, 实现sort.Interface接口的获取元素数量方法
Len() int
// Less 实现sort.Interface接口的比较元素方法
Less(i, j int) bool
// Swap 实现sort.Interface接口的交换元素方法
Swap(i, j int)
// Empty returns an empty Series of the same type
Empty(t ...Type) Series
// Copy 复制
Copy() Series
// Reverse 序列反转
Reverse() Series
// Select 选取一段记录
Select(r api.ScopeLimit) Series
// Append 增加一批记录
Append(values ...any) Series
// Concat concatenates two series together. It will return a new Series with the
// combined elements of both Series.
Concat(x Series) Series
// Records returns the elements of a Series as a []string
Records(round ...bool) []string
// IndexOf 取一条记录, index<0时, 从后往前取值
IndexOf(index int, opt ...any) any
// Set 赋值
Set(index int, v any)
// Subset 获取子集
Subset(start, end int, opt ...any) Series
// Repeat elements of an array.
Repeat(x any, repeats int) Series
// FillNa Fill NA/NaN values using the specified method.
FillNa(v any, inplace bool) Series
// Ref 引用其它周期的数据
Ref(periods any) (s Series)
// Shift index by desired number of periods with an optional time freq.
// 使用可选的时间频率按所需的周期数移动索引.
Shift(periods int) Series
// Rolling 序列化版本
Rolling(param any) RollingAndExpandingMixin
// Apply 接受一个回调函数
Apply(f func(idx int, v any))
// Apply2 增加替换功能, 默认不替换
Apply2(f func(idx int, v any) any, inplace ...bool) Series
// Logic 逻辑处理
Logic(f func(idx int, v any) bool) []bool
// EWM Provide exponentially weighted (EW) calculations.
//
// Exactly one of `com`, `span`, `halflife`, or `alpha` must be
// provided if `times` is not provided. If `times` is provided,
// `halflife` and one of `com`, `span` or `alpha` may be provided.
EWM(alpha EW) ExponentialMovingWindow
// Mean calculates the average value of a series
Mean() num.DType
// StdDev calculates the standard deviation of a series
StdDev() num.DType
// Max 找出最大值
Max() any
// ArgMax Returns the indices of the maximum values along an axis
ArgMax() int
// Min 找出最小值
Min() any
// ArgMin Returns the indices of the minimum values along an axis
ArgMin() int
// Diff 元素的第一个离散差
Diff(param any) (s Series)
// Std 计算标准差
Std() num.DType
// Sum 计算累和
Sum() num.DType
// Add 加
Add(x any) Series
// Sub 减
Sub(x any) Series
// Mul 乘
Mul(x any) Series
// Div 除
Div(x any) Series
// Eq 等于
Eq(x any) Series
// Neq 不等于
Neq(x any) Series
// Gt 大于
Gt(x any) Series
// Gte 大于等于
Gte(x any) Series
// Lt 小于
Lt(x any) Series
// Lte 小于等于
Lte(x any) Series
// And 与
And(x any) Series
// Or 或
Or(x any) Series
// Not 非
Not() Series
}
Series
Data structure for 1-dimensional cross-sectional and time series data 一维横截面和时间序列数据的数据结构 pandas中Series无法确定类型的情况下会使用string保存切片
func Convect ¶
Convect 切片转series
存在可能的强制转换类型
Example ¶
v1 := []float64{1.1, 2.2, 3.3}
v2 := Convect[float64](v1)
fmt.Println(v2)
// Output
// dtype[int]: 1,2,3
func SeriesWithoutName ¶
SeriesWithoutName 创建一个新的匿名Series
type Type ¶
Type is a convenience alias that can be used for a more type safe way of reason and use Series types.
type WriteOption ¶
type WriteOption func(*writeOptions)
WriteOption is the type used to configure the writing of elements
func WriteHeader ¶
func WriteHeader(b bool) WriteOption
WriteHeader sets the writeHeader option for writeOptions.
Source Files
¶
- dataframe.go
- dataframe_csv.go
- dataframe_fillna.go
- dataframe_group.go
- dataframe_indexes.go
- dataframe_join.go
- dataframe_map.go
- dataframe_options.go
- dataframe_records.go
- dataframe_remove.go
- dataframe_select.go
- dataframe_strings.go
- dataframe_struct.go
- dataframe_subset.go
- dataframe_type.go
- ndframe.go
- series.go
- series_convert.go
- series_ewm.go
- series_functions.go
- series_rolling.go
- series_utils.go
- vector.go
- vector_append.go
- vector_basic.go
- vector_ewm.go
- vector_fromnumeric.go
- vector_logic.go
- vector_range.go
- vector_rolling.go
- vector_sort.go
- vector_type.go
