pandas

package module
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 19 Imported by: 32

README

pandas

Sourcegraph Build Status codecov tag license

1. 介绍

golang版本的pandas

2. 功能/模块划分

2.1 特性列表
模块 一级功能 二级功能 进展情况
dataframe dataframe new [√]
dataframe 类型约束 string [√]
dataframe 类型约束 bool [√]
dataframe 类型约束 int64 [√]
dataframe 类型约束 float64 [√]
dataframe 泛型类型 支持全部的基础类型 [√]
dataframe 泛型类型 自动检测类型 [√] 优先级:string > bool > float > int
dataframe align series长度自动对齐 [√]
dataframe col 选择 [√]
dataframe col 新增1列 [√]
dataframe row 删除多行 [√]
dataframe name 改名, 支持单一列改名 [√]
series series new [√] series的列元素类型和reflect.Kind保持一致
series 伪泛型 构建 [√] 再新建series完成之后类型就确定了
series SeriesBool bool类型 [√]
series SeriesString string类型 [√]
series SeriesInt64 int64类型 [√]
series SeriesFloat64 float64类型 [√]
series rolling 支持序列化参数 [√]

3. 示例

3.1. dataframe
3.2. series

4. 参考的的代码:

Documentation

Index

Constants

View Source
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_DTYPE   = SERIES_TYPE_FLOAT64
	SERIES_TYPE_STRING  = reflect.String // string
)

Supported Series Types

View Source
const (
	//MAX_FLOAT32_PRICE = float32(9999.9999) // float32的价最大阀值触发扩展到float64
	MAX_FLOAT32_PRICE = float32(0) // float32的价最大阀值触发扩展到float64
)

Variables

View Source
var (
	DefaultTagName = api.DefaultTagName
)
View Source
var (
	ErrUnsupportedType = exception.New(0, "Unsupported type")
)

Functions

func Rolling added in v1.3.2

func Rolling[T num.BaseType](S []T, N any) [][]T

Rolling returns an array with elements that roll beyond the last position are re-introduced at the first. 滑动窗口, 数据不足是用空数组占位

func ToBool added in v0.6.4

func ToBool(s Series) []bool

func ToFloat32 added in v0.6.4

func ToFloat32(s Series) []float32

ToFloat32 转换Float32

func ToFloat64 added in v0.6.4

func ToFloat64(s Series) []float64

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 added in v0.6.4

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

func NewDataFrame(se ...Series) DataFrame

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 ReadExcel added in v0.6.4

func ReadExcel(filename string, options ...LoadOption) DataFrame

ReadExcel 读取excel文件

func (DataFrame) Col added in v0.6.3

func (self DataFrame) Col(colname string, args ...bool) Series

Col returns a copy of the Series with the given column name contained in the DataFrame. 选取一列

func (DataFrame) ColAsNDArray added in v0.6.6

func (self DataFrame) ColAsNDArray(colname string) Series

func (DataFrame) Concat added in v0.6.16

func (self DataFrame) Concat(dfb DataFrame) DataFrame

func (DataFrame) Dims

func (self DataFrame) Dims() (int, int)

Dims retrieves the dimensions of a DataFrame.

func (DataFrame) Error

func (self DataFrame) Error() error

Returns error or nil if no error occured

func (DataFrame) FillNa added in v0.6.2

func (self DataFrame) FillNa(v any, inplace bool)

FillNa dataframe实现FillNa

func (DataFrame) Filter added in v1.0.5

func (self DataFrame) Filter(columnName string, filter func(kind Type, e any) bool) DataFrame

Filter 过滤

func (DataFrame) Group added in v0.9.15

func (self DataFrame) Group(columnName string, filter func(kind Type, e any) bool) DataFrame

Group 分组

func (DataFrame) IndexOf added in v0.6.18

func (self DataFrame) IndexOf(idx int, opt ...any) map[string]any

IndexOf 取一条记录

idx 为负值时从后往前取

func (DataFrame) Join added in v0.6.3

func (self DataFrame) Join(S ...Series) DataFrame

Join 默认右连接, 加入一个series

func (DataFrame) Names

func (self DataFrame) Names() []string

Names returns the name of the columns on a DataFrame.

func (DataFrame) Ncol

func (self DataFrame) Ncol() int

Ncol returns the number of columns on a DataFrame.

func (DataFrame) Nrow

func (self DataFrame) Nrow() int

Nrow returns the number of rows on a DataFrame.

func (DataFrame) Records

func (self DataFrame) Records(round ...bool) [][]string

Records return the string record representation of a DataFrame.

func (DataFrame) Remove added in v0.6.3

func (self DataFrame) Remove(p api.ScopeLimit) DataFrame

Remove 删除一段范围内的记录

func (DataFrame) Select added in v0.6.3

func (df DataFrame) Select(indexes SelectIndexes) DataFrame

Select the given DataFrame columns

func (DataFrame) SelectRows added in v0.6.4

func (self DataFrame) SelectRows(p api.ScopeLimit) DataFrame

SelectRows 选择一段记录

func (DataFrame) SetName added in v0.6.3

func (self DataFrame) SetName(from string, to string)

SetName 修改一个series的名称

func (DataFrame) SetNames added in v0.6.3

func (self DataFrame) SetNames(colnames ...string) error

SetNames changes the column names of a DataFrame to the ones passed as an argument. 修改全部的列名

func (DataFrame) String

func (self DataFrame) String() (str string)

String implements the Stringer interface for DataFrame

func (DataFrame) Sub added in v0.9.15

func (self DataFrame) Sub(start, end int) DataFrame

Sub 选择一个子集, start end 支持从后到前选择

func (DataFrame) Subset

func (self DataFrame) Subset(start, end int) DataFrame

Subset returns a subset of the rows of the original DataFrame based on the Series subsetting indexes.

func (DataFrame) Types

func (self DataFrame) Types() []string

Types returns the types of the columns on a DataFrame.

func (DataFrame) WriteCSV

func (self DataFrame) WriteCSV(out any, options ...WriteOption) error

WriteCSV writes the DataFrame to the given io.Writer as a CSV file.

支持文件名和io两种方式写入数据

func (DataFrame) WriteExcel added in v0.6.4

func (self DataFrame) WriteExcel(filename string, options ...WriteOption) error

WriteExcel 支持文件名和io两种方式写入数据

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

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 Names

func Names(names ...string) LoadOption

Names sets the names 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 NDArray added in v1.3.2

type NDArray[T num.BaseType] []T

func (NDArray[T]) Add added in v1.3.2

func (self NDArray[T]) Add(x any) Series

func (NDArray[T]) And added in v1.3.2

func (self NDArray[T]) And(x any) Series

func (NDArray[T]) Append added in v1.3.2

func (self NDArray[T]) Append(values ...any) Series

func (NDArray[T]) Apply added in v1.3.2

func (self NDArray[T]) Apply(f func(idx int, v any))

func (NDArray[T]) Apply2 added in v1.3.2

func (self NDArray[T]) Apply2(f func(idx int, v any) any, args ...bool) Series

Apply2 提供可替换功能的apply方法, 默认不替换

func (NDArray[T]) ArgMax added in v1.3.2

func (self NDArray[T]) ArgMax() int

func (NDArray[T]) ArgMin added in v1.3.2

func (self NDArray[T]) ArgMin() int

func (NDArray[T]) Bools added in v1.3.2

func (self NDArray[T]) Bools() []bool

func (NDArray[T]) Concat added in v1.3.2

func (self NDArray[T]) Concat(x Series) Series

func (NDArray[T]) Copy added in v1.3.2

func (self NDArray[T]) Copy() Series

func (NDArray[T]) DTypes added in v1.3.2

func (self NDArray[T]) DTypes() []num.DType

func (NDArray[T]) Diff added in v1.3.2

func (self NDArray[T]) Diff(n any) Series

func (NDArray[T]) Div added in v1.3.2

func (self NDArray[T]) Div(x any) Series

func (NDArray[T]) EWM added in v1.3.2

func (self NDArray[T]) EWM(alpha EW) ExponentialMovingWindow

func (NDArray[T]) Empty added in v1.3.2

func (self NDArray[T]) Empty(tv ...Type) Series

func (NDArray[T]) Eq added in v1.3.2

func (self NDArray[T]) Eq(x any) Series

func (NDArray[T]) FillNa added in v1.3.2

func (self NDArray[T]) FillNa(v any, inplace bool) Series

func (NDArray[T]) Floats added in v1.3.2

func (self NDArray[T]) Floats() []float32

func (NDArray[T]) Gt added in v1.3.2

func (self NDArray[T]) Gt(x any) Series

func (NDArray[T]) Gte added in v1.3.2

func (self NDArray[T]) Gte(x any) Series

func (NDArray[T]) IndexOf added in v1.3.2

func (self NDArray[T]) IndexOf(index int, opt ...any) any

func (NDArray[T]) Ints added in v1.3.2

func (self NDArray[T]) Ints() []num.Int

func (NDArray[T]) Len added in v1.3.2

func (self NDArray[T]) Len() int

func (NDArray[T]) Less added in v1.3.2

func (self NDArray[T]) Less(i, j int) bool

Less 实现sort.Interface接口的比较元素方法

func (NDArray[T]) Logic added in v1.3.2

func (self NDArray[T]) Logic(f func(idx int, v any) bool) []bool

func (NDArray[T]) Lt added in v1.3.2

func (self NDArray[T]) Lt(x any) Series

func (NDArray[T]) Lte added in v1.3.2

func (self NDArray[T]) Lte(x any) Series

func (NDArray[T]) Max added in v1.3.2

func (self NDArray[T]) Max() any

func (NDArray[T]) Mean added in v1.3.2

func (self NDArray[T]) Mean() num.DType

func (NDArray[T]) Min added in v1.3.2

func (self NDArray[T]) Min() any

func (NDArray[T]) Mul added in v1.3.2

func (self NDArray[T]) Mul(x any) Series

func (NDArray[T]) NaN added in v1.3.2

func (self NDArray[T]) NaN() any

func (NDArray[T]) Name added in v1.3.2

func (self NDArray[T]) Name() string

func (NDArray[T]) Neq added in v1.3.2

func (self NDArray[T]) Neq(x any) Series

func (NDArray[T]) Not added in v1.3.2

func (self NDArray[T]) Not() Series

func (NDArray[T]) Or added in v1.3.2

func (self NDArray[T]) Or(x any) Series

func (NDArray[T]) Records added in v1.3.2

func (self NDArray[T]) Records(round ...bool) []string

func (NDArray[T]) Ref added in v1.3.2

func (self NDArray[T]) Ref(n any) Series

func (NDArray[T]) Rename added in v1.3.2

func (self NDArray[T]) Rename(name string)

func (NDArray[T]) Repeat added in v1.3.2

func (self NDArray[T]) Repeat(x any, repeats int) Series

func (NDArray[T]) Reverse added in v1.3.2

func (self NDArray[T]) Reverse() Series

func (NDArray[T]) Rolling added in v1.3.2

func (self NDArray[T]) Rolling(param any) RollingAndExpandingMixin

func (NDArray[T]) Select added in v1.3.2

func (self NDArray[T]) Select(r api.ScopeLimit) Series

func (NDArray[T]) Shift added in v1.3.2

func (self NDArray[T]) Shift(periods int) Series

func (NDArray[T]) Std added in v1.3.2

func (self NDArray[T]) Std() num.DType

func (NDArray[T]) StdDev added in v1.3.2

func (self NDArray[T]) StdDev() num.DType

func (NDArray[T]) Strings added in v1.3.2

func (self NDArray[T]) Strings() []string

func (NDArray[T]) Sub added in v1.3.2

func (self NDArray[T]) Sub(x any) Series

func (NDArray[T]) Subset added in v1.3.2

func (self NDArray[T]) Subset(start, end int, opt ...any) Series

func (NDArray[T]) Sum added in v1.3.2

func (self NDArray[T]) Sum() num.DType

func (NDArray[T]) Swap added in v1.3.2

func (self NDArray[T]) Swap(i, j int)

Swap 实现sort.Interface接口的交换元素方法

func (NDArray[T]) Type added in v1.3.2

func (self NDArray[T]) Type() Type

func (NDArray[T]) Values added in v1.3.2

func (self NDArray[T]) Values() any

type NDFrame

type NDFrame struct {
	// contains filtered or unexported fields
}

NDFrame 这里本意是想做一个父类, 实际的效果是一个抽象类

func FillNa added in v0.6.2

func FillNa[T num.GenericType](s *NDFrame, v T, inplace bool) *NDFrame

FillNa 填充NaN的元素为v inplace为真是修改series元素的值 如果v和Values()返回值的slice类型不一致就会panic

func NewNDFrame

func NewNDFrame[E num.GenericType](name string, rows ...E) *NDFrame

func (*NDFrame) Add added in v0.6.6

func (this *NDFrame) Add(x any) Series

func (*NDFrame) And added in v0.6.7

func (this *NDFrame) And(x any) Series

func (*NDFrame) Append added in v0.6.3

func (this *NDFrame) Append(values ...any) Series

Append 批量增加记录

func (*NDFrame) Apply added in v0.6.3

func (this *NDFrame) Apply(f func(idx int, v any))

func (*NDFrame) Apply2 added in v0.6.16

func (this *NDFrame) Apply2(f func(idx int, v any) any, args ...bool) Series

func (*NDFrame) ArgMax added in v0.6.6

func (this *NDFrame) ArgMax() int

func (*NDFrame) ArgMin added in v0.6.6

func (this *NDFrame) ArgMin() int

func (*NDFrame) Bools added in v0.7.9

func (this *NDFrame) Bools() []bool

func (*NDFrame) Concat added in v0.6.16

func (this *NDFrame) Concat(x Series) Series

func (*NDFrame) Copy

func (this *NDFrame) Copy() Series

Copy 复制一个副本

func (*NDFrame) DTypes added in v0.6.4

func (this *NDFrame) DTypes() []num.DType

DTypes 计算以这个函数为主

func (*NDFrame) Diff added in v0.6.3

func (this *NDFrame) Diff(param any) (s Series)

Diff 元素的第一个离散差 First discrete difference of element. Calculates the difference of a {klass} element compared with another element in the {klass} (default is element in previous row).

func (*NDFrame) Div added in v0.6.6

func (this *NDFrame) Div(x any) Series

func (*NDFrame) EWM added in v0.6.4

func (this *NDFrame) EWM(alpha EW) ExponentialMovingWindow

EWM provides exponential weighted calculations.

func (*NDFrame) Empty

func (this *NDFrame) Empty(t ...Type) Series

func (*NDFrame) Eq added in v0.6.7

func (this *NDFrame) Eq(x any) Series

func (*NDFrame) FillNa added in v0.6.2

func (this *NDFrame) FillNa(v any, inplace bool) Series

func (*NDFrame) Floats added in v0.6.6

func (this *NDFrame) Floats() []float32

func (*NDFrame) Gt added in v0.6.7

func (this *NDFrame) Gt(x any) Series

func (*NDFrame) Gte added in v0.6.7

func (this *NDFrame) Gte(x any) Series

func (*NDFrame) IndexOf added in v0.6.18

func (this *NDFrame) IndexOf(index int, opt ...any) any

func (*NDFrame) Ints added in v0.6.6

func (this *NDFrame) Ints() []num.Int

AsInt 强制转换成整型

func (*NDFrame) Len

func (this *NDFrame) Len() int

Len 获得行数, 实现sort.Interface接口的获取元素数量方法

func (*NDFrame) Less added in v0.6.4

func (this *NDFrame) Less(i, j int) bool

Less 实现sort.Interface接口的比较元素方法

func (*NDFrame) Logic added in v0.6.4

func (this *NDFrame) Logic(f func(idx int, v any) bool) []bool

func (*NDFrame) Lt added in v0.6.7

func (this *NDFrame) Lt(x any) Series

func (*NDFrame) Lte added in v0.6.7

func (this *NDFrame) Lte(x any) Series

func (*NDFrame) Max added in v0.6.2

func (this *NDFrame) Max() any

func (*NDFrame) Mean

func (this *NDFrame) Mean() num.DType

func (*NDFrame) Min added in v0.6.2

func (this *NDFrame) Min() any

func (*NDFrame) Mul added in v0.6.6

func (this *NDFrame) Mul(x any) Series

func (*NDFrame) NaN added in v0.6.4

func (this *NDFrame) NaN() any

NaN 输出默认的NaN

func (*NDFrame) Name

func (this *NDFrame) Name() string

func (*NDFrame) Neq added in v1.2.4

func (this *NDFrame) Neq(x any) Series

func (*NDFrame) Not added in v1.2.4

func (this *NDFrame) Not() Series

func (*NDFrame) Or added in v1.1.0

func (this *NDFrame) Or(x any) Series

func (*NDFrame) Records

func (this *NDFrame) Records(round ...bool) []string

func (*NDFrame) Ref added in v0.6.4

func (this *NDFrame) Ref(param any) (s Series)

func (*NDFrame) Rename

func (this *NDFrame) Rename(n string)

func (*NDFrame) Repeat

func (this *NDFrame) Repeat(x any, repeats int) Series

func (*NDFrame) Reverse added in v0.6.6

func (this *NDFrame) Reverse() Series

func (*NDFrame) Rolling

func (this *NDFrame) Rolling(param any) RollingAndExpandingMixin

Rolling RollingAndExpandingMixin

func (*NDFrame) Select added in v0.6.3

func (this *NDFrame) Select(r api.ScopeLimit) Series

Select 选取一段记录

func (*NDFrame) Shift

func (this *NDFrame) Shift(periods int) Series

func (*NDFrame) Std added in v0.6.4

func (this *NDFrame) Std() num.DType

func (*NDFrame) StdDev

func (this *NDFrame) StdDev() num.DType

func (*NDFrame) Strings added in v0.6.22

func (this *NDFrame) Strings() []string

func (*NDFrame) Sub added in v0.6.6

func (this *NDFrame) Sub(x any) Series

func (*NDFrame) Subset

func (this *NDFrame) Subset(start, end int, opt ...any) Series

func (*NDFrame) Sum added in v0.6.4

func (this *NDFrame) Sum() num.DType

func (*NDFrame) Swap added in v0.6.4

func (this *NDFrame) Swap(i, j int)

Swap 实现sort.Interface接口的交换元素方法

func (*NDFrame) Type

func (this *NDFrame) Type() Type

func (*NDFrame) Values

func (this *NDFrame) Values() any

type RollingAndExpandingMixin added in v0.6.3

type RollingAndExpandingMixin struct {
	Window []num.DType
	Series Series
}

RollingAndExpandingMixin 滚动和扩展静态横切

func (RollingAndExpandingMixin) Apply added in v0.6.4

func (r RollingAndExpandingMixin) Apply(f func(S Series, N num.DType) num.DType) (s Series)

Apply 接受一个回调

func (RollingAndExpandingMixin) Count added in v0.6.4

func (r RollingAndExpandingMixin) Count() (s Series)

func (RollingAndExpandingMixin) GetBlocks added in v1.3.2

func (r RollingAndExpandingMixin) GetBlocks() (blocks []Series)

GetBlocks series分块

func (RollingAndExpandingMixin) Max added in v0.6.4

func (r RollingAndExpandingMixin) Max() (s Series)

func (RollingAndExpandingMixin) Mean added in v0.6.3

func (r RollingAndExpandingMixin) Mean() (s Series)

Mean returns the rolling mean.

func (RollingAndExpandingMixin) Min added in v0.6.4

func (r RollingAndExpandingMixin) Min() (s Series)

func (RollingAndExpandingMixin) Std added in v0.6.4

func (RollingAndExpandingMixin) Sum added in v0.6.4

type SelectIndexes added in v0.6.4

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 {
	// 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

	// Floats 强制转成[]float32
	Floats() []float32
	// DTypes 强制转[]num.DType
	DTypes() []num.DType
	// Ints 强制转换成整型
	Ints() []num.Int
	// 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
	// CloneAndReverse 序列反转
	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
	// 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, args ...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
一维横截面和时间序列数据的数据结构

func Align2Series added in v1.3.2

func Align2Series(x any, N int) Series

Align2Series any转换成series

func GenericSeries

func GenericSeries[T num.GenericType](name string, values ...T) Series

GenericSeries 泛型方法, 构造序列, 比其它方式对类型的统一性要求更严格

func NewNDArray added in v1.3.2

func NewNDArray[T num.BaseType](data ...T) Series

NewNDArray 构建一个新的Series

func NewSeries

func NewSeries(t Type, name string, values any) Series

NewSeries 指定类型创建序列

func NewSeriesWithType added in v0.6.3

func NewSeriesWithType(_type Type, name string, values ...any) Series

NewSeriesWithType 通过类型创新一个新series

func NewSeriesWithoutType added in v0.6.3

func NewSeriesWithoutType(name string, values ...any) Series

NewSeriesWithoutType 不带类型创新一个新series

func ToSeries added in v1.3.2

func ToSeries[T num.BaseType](data ...T) Series

ToSeries 转换切片为Series

type Type

type Type = reflect.Kind

Type is a convenience alias that can be used for a more type safe way of reason and use Series types.

func DetectTypeBySlice added in v1.3.2

func DetectTypeBySlice(arr ...any) (Type, error)

DetectTypeBySlice 检测类型

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL