pandas

package module
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 19 Imported by: 31

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 (
	//MAX_FLOAT32_PRICE = float32(9999.9999) // float32的价最大阀值触发扩展到float64
	MAX_FLOAT32_PRICE = float32(0) // float32的价最大阀值触发扩展到float64
)

Variables

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

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

NewSeriesWithType 通过类型创新一个新series

func NewSeriesWithoutType added in v0.6.3

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

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

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 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) stat.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) stat.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) 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(series 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() [][]string

Records return the string record representation of a DataFrame.

func (DataFrame) Remove added in v0.6.3

func (self DataFrame) Remove(p stat.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 stat.ScopeLimit) DataFrame

Select 选择一段记录

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

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

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

func (*NDFrame) And added in v0.6.7

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

func (*NDFrame) Append added in v0.6.3

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

Append 批量增加记录

func (*NDFrame) Apply added in v0.6.3

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

func (*NDFrame) Apply2 added in v0.6.16

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

func (*NDFrame) ArgMax added in v0.6.6

func (self *NDFrame) ArgMax() int

func (*NDFrame) ArgMin added in v0.6.6

func (self *NDFrame) ArgMin() int

func (*NDFrame) Bools added in v0.7.9

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

func (*NDFrame) Concat added in v0.6.16

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

func (*NDFrame) Copy

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

Copy 复制一个副本

func (*NDFrame) DTypes added in v0.6.4

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

DTypes 计算以这个函数为主

func (*NDFrame) Diff added in v0.6.3

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

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

func (*NDFrame) EWM added in v0.6.4

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

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

func (*NDFrame) FillNa added in v0.6.2

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

func (*NDFrame) Floats added in v0.6.6

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

func (*NDFrame) Gt added in v0.6.7

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

func (*NDFrame) Gte added in v0.6.7

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

func (*NDFrame) IndexOf added in v0.6.18

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

func (*NDFrame) Ints added in v0.6.6

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

AsInt 强制转换成整型

func (*NDFrame) Len

func (self *NDFrame) Len() int

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

func (*NDFrame) Less added in v0.6.4

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

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

func (*NDFrame) Logic added in v0.6.4

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

func (*NDFrame) Lt added in v0.6.7

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

func (*NDFrame) Lte added in v0.6.7

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

func (*NDFrame) Max added in v0.6.2

func (self *NDFrame) Max() any

func (*NDFrame) Mean

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

func (*NDFrame) Min added in v0.6.2

func (self *NDFrame) Min() any

func (*NDFrame) Mul added in v0.6.6

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

func (*NDFrame) NaN added in v0.6.4

func (self *NDFrame) NaN() any

NaN 输出默认的NaN

func (*NDFrame) Name

func (self *NDFrame) Name() string

func (*NDFrame) Records

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

func (*NDFrame) Ref added in v0.6.4

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

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

func (*NDFrame) Rolling

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

Rolling RollingAndExpandingMixin

func (*NDFrame) Select added in v0.6.3

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

Select 选取一段记录

func (*NDFrame) Shift

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

func (*NDFrame) Std added in v0.6.4

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

func (*NDFrame) StdDev

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

func (*NDFrame) Strings added in v0.6.22

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

func (*NDFrame) Sub added in v0.6.6

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

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

func (*NDFrame) Swap added in v0.6.4

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

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

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

func (SeriesString) Apply added in v0.6.6

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

func (SeriesString) Copy

func (self SeriesString) Copy() stat.Series

func (SeriesString) DTypes added in v0.6.6

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

func (SeriesString) Diff added in v0.6.6

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

func (SeriesString) EWM added in v0.6.6

func (SeriesString) Empty

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

func (SeriesString) FillNa added in v0.6.2

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

func (SeriesString) Floats added in v0.6.6

func (self SeriesString) Floats() []float32

func (SeriesString) Ints added in v0.6.6

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

func (SeriesString) Len

func (self SeriesString) Len() int

func (SeriesString) Less added in v0.6.6

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

func (SeriesString) Logic added in v0.6.6

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

func (SeriesString) Max added in v0.6.6

func (self SeriesString) Max() any

func (SeriesString) Mean

func (self SeriesString) Mean() stat.DType

func (SeriesString) Min added in v0.6.6

func (self SeriesString) Min() any

func (SeriesString) NaN added in v0.6.6

func (self SeriesString) NaN() any

func (SeriesString) Name

func (self SeriesString) Name() string

func (SeriesString) Records

func (self SeriesString) Records() []string

func (SeriesString) Ref added in v0.6.6

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

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

func (SeriesString) Shift

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

func (SeriesString) Std added in v0.6.6

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

func (self SeriesString) Sum() stat.DType

func (SeriesString) Swap added in v0.6.6

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
algorithms

Jump to

Keyboard shortcuts

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