pandas

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

README

godas

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 (
	//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 GenericSeries

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

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

func NewSeries

func NewSeries(t stat.Type, name string, vals any) stat.Series

NewSeries 指定类型创建序列

func NewSeriesWithType

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

NewSeriesWithType 通过类型创新一个新series

func NewSeriesWithoutType

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

NewSeriesWithoutType 不带类型创新一个新series

Types

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]interface{}, 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 LoadMatrix

func LoadMatrix(mat mat.Matrix) DataFrame

LoadMatrix loads the given Matrix as a DataFrame TODO: Add Loadoptions

func LoadRecords

func LoadRecords(records [][]string, options ...LoadOption) DataFrame

LoadRecords creates a new DataFrame based on the given records. 这个方法是从本地缓存文件读取数据的第二步, 数据从形式上只能是字符串

func LoadStructs

func LoadStructs(i interface{}, 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 ...stat.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 ReadCSVHead added in v1.0.1

func ReadCSVHead(in any, options ...LoadOption) DataFrame

ReadCSVHead reads a CSV file from a io.Reader and builds a DataFrame with the

resulting records.
支持文件名和io两种方式读取数据

func ReadExcel

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

ReadExcel 读取excel文件

func (DataFrame) Col

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

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

func (DataFrame) ColAsNDArray

func (self DataFrame) ColAsNDArray(colname string) stat.Series

func (DataFrame) Concat

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

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

FillNa dataframe实现FillNa

func (DataFrame) Filter

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

Filter 过滤

func (DataFrame) Group

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

Group 分组

func (DataFrame) IndexOf

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

IndexOf 取一条记录

idx 为负值时从后往前取

func (DataFrame) Join

func (self DataFrame) Join(S ...stat.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

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

Remove 删除一段范围内的记录

func (DataFrame) Select

func (df DataFrame) Select(indexes SelectIndexes) DataFrame

Select the given DataFrame columns

func (DataFrame) SelectRows

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

SelectRows 选择一段记录

func (DataFrame) SetName

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

SetName 修改一个series的名称

func (DataFrame) SetNames

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

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

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

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

type LoadOption

type LoadOption func(*loadOptions)

LoadOption is the type used to configure the load of elements

func DefaultType

func DefaultType(t stat.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]stat.Type) LoadOption

WithTypes sets the types option for loadOptions.

type NDFrame

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

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

func FillNa

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

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

func NewNDFrame

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

func (*NDFrame) Add

func (self *NDFrame) Add(x any) stat.Series

func (*NDFrame) And

func (self *NDFrame) And(x any) stat.Series

func (*NDFrame) Append

func (self *NDFrame) Append(values ...any) stat.Series

Append 批量增加记录

func (*NDFrame) Apply

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

func (*NDFrame) Apply2

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

func (*NDFrame) ArgMax

func (self *NDFrame) ArgMax() int

func (*NDFrame) ArgMin

func (self *NDFrame) ArgMin() int

func (*NDFrame) Bools

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

func (*NDFrame) Concat

func (self *NDFrame) Concat(x stat.Series) stat.Series

func (*NDFrame) Copy

func (self *NDFrame) Copy() stat.Series

Copy 复制一个副本

func (*NDFrame) DTypes

func (self *NDFrame) DTypes() []stat.DType

DTypes 计算以这个函数为主

func (*NDFrame) Diff

func (self *NDFrame) Diff(param any) (s stat.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

func (self *NDFrame) Div(x any) stat.Series

func (*NDFrame) EWM

func (s *NDFrame) EWM(alpha stat.EW) stat.ExponentialMovingWindow

EWM provides exponential weighted calculations.

func (*NDFrame) Empty

func (self *NDFrame) Empty(t ...stat.Type) stat.Series

func (*NDFrame) Eq

func (self *NDFrame) Eq(x any) stat.Series

func (*NDFrame) FillNa

func (self *NDFrame) FillNa(v any, inplace bool, fillEmpty bool) stat.Series

func (*NDFrame) Floats

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

func (*NDFrame) Gt

func (self *NDFrame) Gt(x any) stat.Series

func (*NDFrame) Gte

func (self *NDFrame) Gte(x any) stat.Series

func (*NDFrame) IndexOf

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

func (*NDFrame) Ints

func (self *NDFrame) Ints() []stat.Int

AsInt 强制转换成整型

func (*NDFrame) Len

func (self *NDFrame) Len() int

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

func (*NDFrame) Less

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

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

func (*NDFrame) Logic

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

func (*NDFrame) Lt

func (self *NDFrame) Lt(x any) stat.Series

func (*NDFrame) Lte

func (self *NDFrame) Lte(x any) stat.Series

func (*NDFrame) Max

func (self *NDFrame) Max() any

func (*NDFrame) Mean

func (self *NDFrame) Mean() stat.DType

func (*NDFrame) Min

func (self *NDFrame) Min() any

func (*NDFrame) Mul

func (self *NDFrame) Mul(x any) stat.Series

func (*NDFrame) NaN

func (self *NDFrame) NaN() any

NaN 输出默认的NaN

func (*NDFrame) Name

func (self *NDFrame) Name() string

func (*NDFrame) Or

func (self *NDFrame) Or(x any) stat.Series

func (*NDFrame) Records

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

func (*NDFrame) Ref

func (self *NDFrame) Ref(param any) (s stat.Series)

func (*NDFrame) Rename

func (self *NDFrame) Rename(n string)

func (*NDFrame) Repeat

func (self *NDFrame) Repeat(x any, repeats int) stat.Series

func (*NDFrame) Reverse

func (self *NDFrame) Reverse() stat.Series

func (*NDFrame) Rolling

func (self *NDFrame) Rolling(param any) stat.RollingAndExpandingMixin

Rolling RollingAndExpandingMixin

func (*NDFrame) Select

func (self *NDFrame) Select(r api.ScopeLimit) stat.Series

Select 选取一段记录

func (*NDFrame) Shift

func (self *NDFrame) Shift(periods int) stat.Series

func (*NDFrame) Std

func (self *NDFrame) Std() stat.DType

func (*NDFrame) StdDev

func (self *NDFrame) StdDev() stat.DType

func (*NDFrame) Strings

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

func (*NDFrame) Sub

func (self *NDFrame) Sub(x any) stat.Series

func (*NDFrame) Subset

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

func (*NDFrame) Sum

func (self *NDFrame) Sum() stat.DType

func (*NDFrame) Swap

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

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

func (*NDFrame) Type

func (self *NDFrame) Type() stat.Type

func (*NDFrame) Values

func (self *NDFrame) Values() any

type SelectIndexes

type SelectIndexes interface{}

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 SeriesString

type SeriesString struct {
	stat.NDArray[string]
	// contains filtered or unexported fields
}

func (SeriesString) Append

func (self SeriesString) Append(values ...any) stat.Series

func (SeriesString) Apply

func (self SeriesString) Apply(f func(idx int, v any))

func (SeriesString) Copy

func (self SeriesString) Copy() stat.Series

func (SeriesString) DTypes

func (self SeriesString) DTypes() []stat.DType

func (SeriesString) Diff

func (self SeriesString) Diff(param any) (s stat.Series)

func (SeriesString) EWM

func (SeriesString) Empty

func (self SeriesString) Empty(t ...stat.Type) stat.Series

func (SeriesString) FillNa

func (self SeriesString) FillNa(v any, inplace bool) stat.Series

func (SeriesString) Floats

func (self SeriesString) Floats() []float32

func (SeriesString) Ints

func (self SeriesString) Ints() []stat.Int

func (SeriesString) Len

func (self SeriesString) Len() int

func (SeriesString) Less

func (self SeriesString) Less(i, j int) bool

func (SeriesString) Logic

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

func (SeriesString) Max

func (self SeriesString) Max() any

func (SeriesString) Mean

func (self SeriesString) Mean() stat.DType

func (SeriesString) Min

func (self SeriesString) Min() any

func (SeriesString) NaN

func (self SeriesString) NaN() any

func (SeriesString) Name

func (self SeriesString) Name() string

func (SeriesString) Records

func (self SeriesString) Records() []string

func (SeriesString) Ref

func (self SeriesString) Ref(param any) (s stat.Series)

func (SeriesString) Rename

func (self SeriesString) Rename(name string)

func (SeriesString) Repeat

func (self SeriesString) Repeat(x any, repeats int) stat.Series

func (SeriesString) Rolling

func (self SeriesString) Rolling(param any) stat.RollingAndExpandingMixin

func (SeriesString) Select

func (self SeriesString) Select(r api.ScopeLimit) stat.Series

func (SeriesString) Shift

func (self SeriesString) Shift(periods int) stat.Series

func (SeriesString) Std

func (self SeriesString) Std() stat.DType

func (SeriesString) StdDev

func (self SeriesString) StdDev() stat.DType

func (SeriesString) Subset

func (self SeriesString) Subset(start, end int, opt ...any) stat.Series

func (SeriesString) Sum

func (self SeriesString) Sum() stat.DType

func (SeriesString) Swap

func (self SeriesString) Swap(i, j int)

func (SeriesString) Type

func (self SeriesString) Type() stat.Type

func (SeriesString) Values

func (self SeriesString) Values() any

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