dataframe

package module
Version: v0.0.0-...-a103044 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 16 Imported by: 41

README

⭐   the project to show your appreciation. :arrow_upper_right:

dataframe-go

Dataframes are used for statistics, machine-learning, and data manipulation/exploration. You can think of a Dataframe as an excel spreadsheet. This package is designed to be light-weight and intuitive.

⚠️ The package is production ready but the API is not stable yet. Once Go 1.18 (Generics) is introduced, the ENTIRE package will be rewritten. For example, there will only be 1 generic Series type. After that, version 1.0.0 will be tagged.

It is recommended your package manager locks to a commit id instead of the master branch directly. ⚠️

Features

  1. Importing from CSV, JSONL, Parquet, MySQL & PostgreSQL
  2. Exporting to CSV, JSONL, Excel, Parquet, MySQL & PostgreSQL
  3. Developer Friendly
  4. Flexible - Create custom Series (custom data types)
  5. Performant
  6. Interoperability with gonum package.
  7. pandas sub-package Help Required
  8. Fake data generation
  9. Interpolation (ForwardFill, BackwardFill, Linear, Spline, Lagrange)
  10. Time-series Forecasting (SES, Holt-Winters)
  11. Math functions
  12. Plotting (cross-platform)

See Tutorial here.

Installation

go get -u github.com/rocketlaunchr/dataframe-go
import dataframe "github.com/rocketlaunchr/dataframe-go"

DataFrames

Creating a DataFrame


s1 := dataframe.NewSeriesInt64("day", nil, 1, 2, 3, 4, 5, 6, 7, 8)
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, 23.4, 56.2, nil, nil, 84.2, 72, 89)
df := dataframe.NewDataFrame(s1, s2)

fmt.Print(df.Table())
  
OUTPUT:
+-----+-------+---------+
|     |  DAY  |  SALES  |
+-----+-------+---------+
| 0:  |   1   |  50.3   |
| 1:  |   2   |  23.4   |
| 2:  |   3   |  56.2   |
| 3:  |   4   |   NaN   |
| 4:  |   5   |   NaN   |
| 5:  |   6   |  84.2   |
| 6:  |   7   |   72    |
| 7:  |   8   |   89    |
+-----+-------+---------+
| 8X2 | INT64 | FLOAT64 |
+-----+-------+---------+

Go Playground

Insert and Remove Row


df.Append(nil, 9, 123.6)

df.Append(nil, map[string]interface{}{
	"day":   10,
	"sales": nil,
})

df.Remove(0)

OUTPUT:
+-----+-------+---------+
|     |  DAY  |  SALES  |
+-----+-------+---------+
| 0:  |   2   |  23.4   |
| 1:  |   3   |  56.2   |
| 2:  |   4   |   NaN   |
| 3:  |   5   |   NaN   |
| 4:  |   6   |  84.2   |
| 5:  |   7   |   72    |
| 6:  |   8   |   89    |
| 7:  |   9   |  123.6  |
| 8:  |  10   |   NaN   |
+-----+-------+---------+
| 9X2 | INT64 | FLOAT64 |
+-----+-------+---------+

Go Playground

Update Row


df.UpdateRow(0, nil, map[string]interface{}{
	"day":   3,
	"sales": 45,
})

Sorting


sks := []dataframe.SortKey{
	{Key: "sales", Desc: true},
	{Key: "day", Desc: true},
}

df.Sort(ctx, sks)

OUTPUT:
+-----+-------+---------+
|     |  DAY  |  SALES  |
+-----+-------+---------+
| 0:  |   9   |  123.6  |
| 1:  |   8   |   89    |
| 2:  |   6   |  84.2   |
| 3:  |   7   |   72    |
| 4:  |   3   |  56.2   |
| 5:  |   2   |  23.4   |
| 6:  |  10   |   NaN   |
| 7:  |   5   |   NaN   |
| 8:  |   4   |   NaN   |
+-----+-------+---------+
| 9X2 | INT64 | FLOAT64 |
+-----+-------+---------+

Go Playground

Iterating

You can change the step and starting row. It may be wise to lock the DataFrame before iterating.

The returned value is a map containing the name of the series (string) and the index of the series (int) as keys.


iterator := df.ValuesIterator(dataframe.ValuesOptions{0, 1, true}) // Don't apply read lock because we are write locking from outside.

df.Lock()
for {
	row, vals, _ := iterator()
	if row == nil {
		break
	}
	fmt.Println(*row, vals)
}
df.Unlock()

OUTPUT:
0 map[day:1 0:1 sales:50.3 1:50.3]
1 map[sales:23.4 1:23.4 day:2 0:2]
2 map[day:3 0:3 sales:56.2 1:56.2]
3 map[1:<nil> day:4 0:4 sales:<nil>]
4 map[day:5 0:5 sales:<nil> 1:<nil>]
5 map[sales:84.2 1:84.2 day:6 0:6]
6 map[day:7 0:7 sales:72 1:72]
7 map[day:8 0:8 sales:89 1:89]

Go Playground

Statistics

You can easily calculate statistics for a Series using the gonum or montanaflynn/stats package.

SeriesFloat64 and SeriesTime provide access to the exported Values field to seamlessly interoperate with external math-based packages.

Example

Some series provide easy conversion using the ToSeriesFloat64 method.

import "gonum.org/v1/gonum/stat"

s := dataframe.NewSeriesInt64("random", nil, 1, 2, 3, 4, 5, 6, 7, 8)
sf, _ := s.ToSeriesFloat64(ctx)
Mean
mean := stat.Mean(sf.Values, nil)
Median
import "github.com/montanaflynn/stats"
median, _ := stats.Median(sf.Values)
Standard Deviation
std := stat.StdDev(sf.Values, nil)

Plotting (cross-platform)

import (
	chart "github.com/wcharczuk/go-chart"
	"github.com/rocketlaunchr/dataframe-go/plot"
	wc "github.com/rocketlaunchr/dataframe-go/plot/wcharczuk/go-chart"
)

sales := dataframe.NewSeriesFloat64("sales", nil, 50.3, nil, 23.4, 56.2, 89, 32, 84.2, 72, 89)
cs, _ := wc.S(ctx, sales, nil, nil)

graph := chart.Chart{Series: []chart.Series{cs}}

plt, _ := plot.Open("Monthly sales", 450, 300)
graph.Render(chart.SVG, plt)
plt.Display(plot.None)
<-plt.Closed

Output:

plot

Math Functions

import "github.com/rocketlaunchr/dataframe-go/math/funcs"

res := 24
sx := dataframe.NewSeriesFloat64("x", nil, utils.Float64Seq(1, float64(res), 1))
sy := dataframe.NewSeriesFloat64("y", &dataframe.SeriesInit{Size: res})
df := dataframe.NewDataFrame(sx, sy)

fn := funcs.RegFunc("sin(2*𝜋*x/24)")
funcs.Evaluate(ctx, df, fn, 1)

Go Playground

Output:

sine wave

Importing Data

The imports sub-package has support for importing csv, jsonl, parquet, and directly from a SQL database. The DictateDataType option can be set to specify the true underlying data type. Alternatively, InferDataTypes option can be set.

CSV
csvStr := `
Country,Date,Age,Amount,Id
"United States",2012-02-01,50,112.1,01234
"United States",2012-02-01,32,321.31,54320
"United Kingdom",2012-02-01,17,18.2,12345
"United States",2012-02-01,32,321.31,54320
"United Kingdom",2012-05-07,NA,18.2,12345
"United States",2012-02-01,32,321.31,54320
"United States",2012-02-01,32,321.31,54320
Spain,2012-02-01,66,555.42,00241
`
df, err := imports.LoadFromCSV(ctx, strings.NewReader(csvStr))

OUTPUT:
+-----+----------------+------------+-------+---------+-------+
|     |    COUNTRY     |    DATE    |  AGE  | AMOUNT  |  ID   |
+-----+----------------+------------+-------+---------+-------+
| 0:  | United States  | 2012-02-01 |  50   |  112.1  | 1234  |
| 1:  | United States  | 2012-02-01 |  32   | 321.31  | 54320 |
| 2:  | United Kingdom | 2012-02-01 |  17   |  18.2   | 12345 |
| 3:  | United States  | 2012-02-01 |  32   | 321.31  | 54320 |
| 4:  | United Kingdom | 2015-05-07 |  NaN  |  18.2   | 12345 |
| 5:  | United States  | 2012-02-01 |  32   | 321.31  | 54320 |
| 6:  | United States  | 2012-02-01 |  32   | 321.31  | 54320 |
| 7:  |     Spain      | 2012-02-01 |  66   | 555.42  |  241  |
+-----+----------------+------------+-------+---------+-------+
| 8X5 |     STRING     |    TIME    | INT64 | FLOAT64 | INT64 |
+-----+----------------+------------+-------+---------+-------+

Go Playground

Exporting Data

The exports sub-package has support for exporting to csv, jsonl, parquet, Excel and directly to a SQL database.

Optimizations

  • If you know the number of rows in advance, you can set the capacity of the underlying slice of a series using SeriesInit{}. This will preallocate memory and provide speed improvements.

Generic Series

Out of the box, there is support for string, time.Time, float64 and int64. Automatic support exists for float32 and all types of integers. There is a convenience function provided for dealing with bool. There is also support for complex128 inside the xseries subpackage.

There may be times that you want to use your own custom data types. You can either implement your own Series type (more performant) or use the Generic Series (more convenient).

civil.Date

import "time"
import "cloud.google.com/go/civil"

sg := dataframe.NewSeriesGeneric("date", civil.Date{}, nil, civil.Date{2018, time.May, 01}, civil.Date{2018, time.May, 02}, civil.Date{2018, time.May, 03})
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, 23.4, 56.2)

df := dataframe.NewDataFrame(sg, s2)

OUTPUT:
+-----+------------+---------+
|     |    DATE    |  SALES  |
+-----+------------+---------+
| 0:  | 2018-05-01 |  50.3   |
| 1:  | 2018-05-02 |  23.4   |
| 2:  | 2018-05-03 |  56.2   |
+-----+------------+---------+
| 3X2 | CIVIL DATE | FLOAT64 |
+-----+------------+---------+

Tutorial

Create some fake data

Let's create a list of 8 "fake" employees with a name, title and base hourly wage rate.

import "golang.org/x/exp/rand"
import "rocketlaunchr/dataframe-go/utils/faker"

src := rand.NewSource(uint64(time.Now().UTC().UnixNano()))
df := faker.NewDataFrame(8, src, faker.S("name", 0, "Name"), faker.S("title", 0.5, "JobTitle"), faker.S("base rate", 0, "Number", 15, 50))
+-----+----------------+----------------+-----------+
|     |      NAME      |     TITLE      | BASE RATE |
+-----+----------------+----------------+-----------+
| 0:  | Cordia Jacobi  |   Consultant   |    42     |
| 1:  | Nickolas Emard |      NaN       |    22     |
| 2:  | Hollis Dickens | Representative |    22     |
| 3:  | Stacy Dietrich |      NaN       |    43     |
| 4:  |  Aleen Legros  |    Officer     |    21     |
| 5:  |  Adelia Metz   |   Architect    |    18     |
| 6:  | Sunny Gerlach  |      NaN       |    28     |
| 7:  | Austin Hackett |      NaN       |    39     |
+-----+----------------+----------------+-----------+
| 8X3 |     STRING     |     STRING     |   INT64   |
+-----+----------------+----------------+-----------+

Apply Function

Let's give a promotion to everyone by doubling their salary.

s := df.Series[2]

applyFn := dataframe.ApplySeriesFn(func(val interface{}, row, nRows int) interface{} {
	return 2 * val.(int64)
})

dataframe.Apply(ctx, s, applyFn, dataframe.FilterOptions{InPlace: true})
+-----+----------------+----------------+-----------+
|     |      NAME      |     TITLE      | BASE RATE |
+-----+----------------+----------------+-----------+
| 0:  | Cordia Jacobi  |   Consultant   |    84     |
| 1:  | Nickolas Emard |      NaN       |    44     |
| 2:  | Hollis Dickens | Representative |    44     |
| 3:  | Stacy Dietrich |      NaN       |    86     |
| 4:  |  Aleen Legros  |    Officer     |    42     |
| 5:  |  Adelia Metz   |   Architect    |    36     |
| 6:  | Sunny Gerlach  |      NaN       |    56     |
| 7:  | Austin Hackett |      NaN       |    78     |
+-----+----------------+----------------+-----------+
| 8X3 |     STRING     |     STRING     |   INT64   |
+-----+----------------+----------------+-----------+

Create a Time series

Let's inform all employees separately on sequential days.

import "rocketlaunchr/dataframe-go/utils/utime"

mts, _ := utime.NewSeriesTime(ctx, "meeting time", "1D", time.Now().UTC(), false, utime.NewSeriesTimeOptions{Size: &[]int{8}[0]})
df.AddSeries(mts, nil)
+-----+----------------+----------------+-----------+--------------------------------+
|     |      NAME      |     TITLE      | BASE RATE |          MEETING TIME          |
+-----+----------------+----------------+-----------+--------------------------------+
| 0:  | Cordia Jacobi  |   Consultant   |    84     |   2020-02-02 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 1:  | Nickolas Emard |      NaN       |    44     |   2020-02-03 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 2:  | Hollis Dickens | Representative |    44     |   2020-02-04 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 3:  | Stacy Dietrich |      NaN       |    86     |   2020-02-05 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 4:  |  Aleen Legros  |    Officer     |    42     |   2020-02-06 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 5:  |  Adelia Metz   |   Architect    |    36     |   2020-02-07 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 6:  | Sunny Gerlach  |      NaN       |    56     |   2020-02-08 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 7:  | Austin Hackett |      NaN       |    78     |   2020-02-09 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
+-----+----------------+----------------+-----------+--------------------------------+
| 8X4 |     STRING     |     STRING     |   INT64   |              TIME              |
+-----+----------------+----------------+-----------+--------------------------------+

Filtering

Let's filter out our senior employees (they have titles) for no reason.

filterFn := dataframe.FilterDataFrameFn(func(vals map[interface{}]interface{}, row, nRows int) (dataframe.FilterAction, error) {
	if vals["title"] == nil {
		return dataframe.DROP, nil
	}
	return dataframe.KEEP, nil
})

seniors, _ := dataframe.Filter(ctx, df, filterFn)
+-----+----------------+----------------+-----------+--------------------------------+
|     |      NAME      |     TITLE      | BASE RATE |          MEETING TIME          |
+-----+----------------+----------------+-----------+--------------------------------+
| 0:  | Cordia Jacobi  |   Consultant   |    84     |   2020-02-02 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 1:  | Hollis Dickens | Representative |    44     |   2020-02-04 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 2:  |  Aleen Legros  |    Officer     |    42     |   2020-02-06 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
| 3:  |  Adelia Metz   |   Architect    |    36     |   2020-02-07 23:13:53.015324   |
|     |                |                |           |           +0000 UTC            |
+-----+----------------+----------------+-----------+--------------------------------+
| 4X4 |     STRING     |     STRING     |   INT64   |              TIME              |
+-----+----------------+----------------+-----------+--------------------------------+

Other useful packages

  • awesome-svelte - Resources for killing react
  • dbq - Zero boilerplate database operations for Go
  • electron-alert - SweetAlert2 for Electron Applications
  • google-search - Scrape google search results
  • igo - A Go transpiler with cool new syntax such as fordefer (defer for for-loops)
  • mysql-go - Properly cancel slow MySQL queries
  • react - Build front end applications using Go
  • remember-go - Cache slow database queries
  • testing-go - Testing framework for unit testing

The license is a modified MIT license. Refer to LICENSE file for more details.

© 2018-21 PJ Engineering and Business Solutions Pty. Ltd.

Documentation

Index

Constants

View Source
const (
	// FALSE is used convert a false (bool) to an int.
	FALSE = 0
	// TRUE is used convert a true (bool) to an int.
	TRUE = 1
)

Variables

View Source
var DontLock = dontLock

DontLock is short-hand for various functions that permit disabling locking.

View Source
var ErrNoRows = errors.New("contains no rows")

ErrNoRows signifies that the Series, Dataframe or import data contains no rows of data.

Functions

func Apply

func Apply(ctx context.Context, sdf interface{}, fn interface{}, opts ...FilterOptions) (interface{}, error)

Apply will call fn for each row in the Series or DataFrame and replace the existing value with the new value returned by fn. When sdf is a DataFrame, fn must be of type ApplyDataFrameFn. When sdf is a Series, fn must be of type ApplySeriesFn.

func B

func B(b bool) int

B converts a boolean to an int.

func BoolValueFormatter

func BoolValueFormatter(v interface{}) string

BoolValueFormatter is used by SetValueToStringFormatter to display an int as a bool. If the encountered value is not a 0 or 1, it will panic.

func DefaultIsEqualFunc

func DefaultIsEqualFunc(a, b interface{}) bool

DefaultIsEqualFunc is the default comparitor to determine if two values in the series are the same.

func DefaultValueFormatter

func DefaultValueFormatter(v interface{}) string

DefaultValueFormatter will return a string representation of the data in a particular row.

func Filter

func Filter(ctx context.Context, sdf interface{}, fn interface{}, opts ...FilterOptions) (interface{}, error)

Filter is used to filter particular rows in a Series or DataFrame. If the InPlace option is set, the Series or DataFrame is modified "in place" and the function returns nil. Alternatively, a new Series or DataFrame is returned.

When sdf is a DataFrame, fn must be of type FilterDataFrameFn. When sdf is a Series, fn must be of type FilterSeriesFn.

func IsValidFloat64

func IsValidFloat64(f float64) bool

IsValidFloat64 returns true if f is neither Nan nor ±Inf. Otherwise it returns false.

Types

type ApplyDataFrameFn

type ApplyDataFrameFn func(vals map[interface{}]interface{}, row, nRows int) map[interface{}]interface{}

ApplyDataFrameFn is used by the Apply function when used with DataFrames. vals contains the values for the current row. The keys contain ints (index of Series) and strings (name of Series). The returned map must only contain what values you intend to update. The key can be a string (name of Series) or int (index of Series). If nil is returned, the existing values for the row are unchanged.

type ApplySeriesFn

type ApplySeriesFn func(val interface{}, row, nRows int) interface{}

ApplySeriesFn is used by the Apply function when used with Series. val contains the value of the current row. The returned value is the updated value.

type AsciiGraphOptions

type AsciiGraphOptions struct {

	// Caption sets the graph's caption.
	Caption string

	// Height sets the graph's height.
	Height int

	// Offset sets the graph's offset.
	Offset int

	// Width sets the graph's width. By default, the width of the graph is determined by the number of data points.
	// If the value given is a positive number, the data points are interpolated on the x axis. Values <= 0 reset the width to the default value.
	Width int

	// R is used to limit the range of rows.
	R *Range
}

AsciiGraphOptions can be used to configure the look of the graph.

type DataFrame

type DataFrame struct {
	Series []Series
	// contains filtered or unexported fields
}

DataFrame allows you to handle numerous series of data conveniently.

func NewDataFrame

func NewDataFrame(se ...Series) *DataFrame

NewDataFrame creates a new dataframe.

func (*DataFrame) AddSeries

func (df *DataFrame) AddSeries(s Series, colN *int, opts ...Options) error

AddSeries will add a Series to the end of the DataFrame, unless set by ColN.

func (*DataFrame) Append

func (df *DataFrame) Append(opts *Options, vals ...interface{})

Append inserts a row at the end.

func (*DataFrame) ClearRow

func (df *DataFrame) ClearRow(row int, opts ...Options)

ClearRow makes an entire row nil.

func (*DataFrame) Copy

func (df *DataFrame) Copy(r ...Range) *DataFrame

Copy will create a new copy of the Dataframe. It is recommended that you lock the Dataframe before attempting to Copy.

func (*DataFrame) FillRand

func (df *DataFrame) FillRand(src rand.Source, probNil float64, rander Rander, opts ...FillRandOptions)

FillRand will randomly fill all the Series in the Dataframe.

func (*DataFrame) Insert

func (df *DataFrame) Insert(row int, opts *Options, vals ...interface{})

Insert adds a row to a particular position.

func (*DataFrame) IsEqual

func (df *DataFrame) IsEqual(ctx context.Context, df2 *DataFrame, opts ...IsEqualOptions) (bool, error)

IsEqual returns true if df2's values are equal to df.

func (*DataFrame) Lock

func (df *DataFrame) Lock(deepLock ...bool)

Lock will lock the Dataframe allowing you to directly manipulate the underlying Series with confidence.

func (*DataFrame) MustNameToColumn

func (df *DataFrame) MustNameToColumn(seriesName string, opts ...Options) int

MustNameToColumn returns the index of the series based on the name. The starting index is 0. If seriesName doesn't exist it panics.

func (*DataFrame) NRows

func (df *DataFrame) NRows(opts ...Options) int

NRows returns the number of rows of data. Each series must contain the same number of rows.

func (*DataFrame) NameToColumn

func (df *DataFrame) NameToColumn(seriesName string, opts ...Options) (int, error)

NameToColumn returns the index of the series based on the name. The starting index is 0.

func (*DataFrame) Names

func (df *DataFrame) Names(opts ...Options) []string

Names will return a list of all the series names.

func (*DataFrame) Prepend

func (df *DataFrame) Prepend(opts *Options, vals ...interface{})

Prepend inserts a row at the beginning.

func (*DataFrame) Remove

func (df *DataFrame) Remove(row int, opts ...Options)

Remove deletes a row.

func (*DataFrame) RemoveSeries

func (df *DataFrame) RemoveSeries(seriesName string, opts ...Options) error

RemoveSeries will remove a Series from the Dataframe.

func (*DataFrame) ReorderColumns

func (df *DataFrame) ReorderColumns(newOrder []string, opts ...Options) error

ReorderColumns reorders the columns based on an ordered list of column names. The length of newOrder must match the number of columns in the Dataframe. The column names in newOrder must be unique.

func (*DataFrame) Row

func (df *DataFrame) Row(row int, dontReadLock bool, retOpt ...SeriesReturnOpt) map[interface{}]interface{}

Row returns the series' values for a particular row.

Example:

df.Row(5, false, dataframe.SeriesIdx|dataframe.SeriesName)

func (*DataFrame) Sort

func (df *DataFrame) Sort(ctx context.Context, keys []SortKey, opts ...SortOptions) (completed bool)

Sort is used to sort the Dataframe according to different keys. It will return true if sorting was completed or false when the context is canceled.

func (*DataFrame) String

func (df *DataFrame) String() string

String implements the fmt.Stringer interface. It does not lock the DataFrame.

func (*DataFrame) Swap

func (df *DataFrame) Swap(row1, row2 int, opts ...Options)

Swap is used to swap 2 values based on their row position.

func (*DataFrame) Table

func (df *DataFrame) Table(opts ...TableOptions) string

Table will produce the DataFrame in a table.

func (*DataFrame) Unlock

func (df *DataFrame) Unlock(deepUnlock ...bool)

Unlock will unlock the Dataframe that was previously locked.

func (*DataFrame) Update

func (df *DataFrame) Update(row int, col interface{}, val interface{}, opts ...Options)

Update is used to update a specific entry. col can be the name of the series or the column number.

func (*DataFrame) UpdateRow

func (df *DataFrame) UpdateRow(row int, opts *Options, vals ...interface{})

UpdateRow will update an entire row.

func (*DataFrame) ValuesIterator

func (df *DataFrame) ValuesIterator(opts ...ValuesOptions) func(opts ...SeriesReturnOpt) (*int, map[interface{}]interface{}, int)

ValuesIterator will return a function that can be used to iterate through all the values.

The returned value is a map containing the name of the series (string) and the index of the series (int) as keys. You can reduce the keys in the map to only contain the series name (SeriesName) or series index (SeriesIdx).

Example:

iterator := df.ValuesIterator(dataframe.ValuesOptions{0, 1, true})

df.Lock()
for {
   row, vals, _ := iterator(dataframe.SeriesName)
   if row == nil {
      break
   }
   fmt.Println(*row, vals)
}
df.Unlock()

// OR

df.Lock()
row, vals, _ := iterator()
for ; row != nil; row, vals, _ = iterator() {
   fmt.Println(*row, vals)
}
df.Unlock()

type ErrorCollection

type ErrorCollection struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ErrorCollection is used to hold multiple errors.

func NewErrorCollection

func NewErrorCollection() *ErrorCollection

NewErrorCollection returns a new ErrorCollection. ErrorCollection is compatible with errors.Is and errors.As functions.

func (*ErrorCollection) AddError

func (ec *ErrorCollection) AddError(err error, lock ...bool)

AddError inserts a new error to the ErrorCollection. If err is nil, the function will panic.

func (*ErrorCollection) As

func (ec *ErrorCollection) As(target interface{}) bool

As returns true if ErrorCollection contains an error of the same type as target. If so, it will set target to that error.

func (*ErrorCollection) Error

func (ec *ErrorCollection) Error() string

Error implements the error interface.

func (*ErrorCollection) Is

func (ec *ErrorCollection) Is(err error) bool

Is returns true if ErrorCollection contains err.

func (*ErrorCollection) IsNil

func (ec *ErrorCollection) IsNil(lock ...bool) bool

IsNil returns whether the ErrorCollection contains any errors.

type FillRandOptions

type FillRandOptions struct {

	// R is used to only randomly fill a range of rows.
	R *Range

	// Extra is used to pass extra custom data.
	Extra interface{}
}

FillRandOptions configures how FillRand should behave.

type FillRander

type FillRander interface {

	// FillRand will fill a Series with random data. probNil is a value between between 0 and 1 which
	// determines if a row is given a nil value.
	//
	// Example:
	//
	//  import "golang.org/x/exp/rand"
	//  import "gonum.org/v1/gonum/stat/distuv"
	//  import "time"
	//
	//  src := rand.NewSource(uint64(time.Now().UTC().UnixNano()))
	//  uniform := distuv.Uniform{Min: 0, Max: 10000, Src: src}
	//  s.FillRand(src, 0.5, uniform)
	//
	FillRand(src rand.Source, probNil float64, rander Rander, opts ...FillRandOptions)
}

FillRander is an interface for generating a Series with random values.

type FilterAction

type FilterAction int

FilterAction is the return value of FilterSeriesFn and FilterDataFrameFn.

const (
	// DROP is used to signify that a row must be dropped.
	DROP FilterAction = 0

	// KEEP is used to signify that a row must be kept.
	KEEP FilterAction = 1

	// CHOOSE is used to signify that a row must be kept.
	CHOOSE FilterAction = 1
)

type FilterDataFrameFn

type FilterDataFrameFn func(vals map[interface{}]interface{}, row, nRows int) (FilterAction, error)

FilterDataFrameFn is used by the Filter function to determine which rows are selected. vals contains the values for the current row. The keys contain ints (index of Series) and strings (name of Series). If the function returns DROP, then the row is removed. If KEEP or CHOOSE is chosen, the row is kept.

type FilterOptions

type FilterOptions struct {

	// InPlace will perform the filter operation on the current Series or DataFrame.
	// If InPlace is not set, a new Series or DataFrame will be returned with rows based
	// on the filter operation. The original Series or DataFrame will be unmodified.
	InPlace bool

	// DontLock can be set to true if the Series should not be locked.
	DontLock bool
}

FilterOptions modifies the behavior of the Filter function.

type FilterSeriesFn

type FilterSeriesFn func(val interface{}, row, nRows int) (FilterAction, error)

FilterSeriesFn is used by the Filter function to determine which rows are selected. val contains the value of the current row. If the function returns DROP, then the row is removed. If KEEP or CHOOSE is chosen, the row is kept.

type IsEqualFunc

type IsEqualFunc func(a, b interface{}) bool

IsEqualFunc is used to determine if a and b are considered equal.

type IsEqualOptions

type IsEqualOptions struct {

	// Don't apply lock.
	DontLock bool

	// Check if name is the same.
	CheckName bool
}

IsEqualOptions sets various options for the IsEqual function.

type IsLessThanFunc

type IsLessThanFunc func(a, b interface{}) bool

IsLessThanFunc returns true if a < b

type NewSerieser

type NewSerieser interface {

	// NewSeries creates a new initialized Series of the same type.
	NewSeries(name string, init *SeriesInit) Series
}

NewSerieser is an interface for a Series to create a new initialized Series of the same type.

type NilCountOptions

type NilCountOptions struct {

	// Ctx adds a context.
	Ctx context.Context

	// R is used to limit the range.
	R *Range

	// Don't apply lock.
	DontLock bool

	// When StopAtOneNil is set, the function will return after finding at least 1 nil value.
	// It can be used as a ContainsNil function when used with R.
	StopAtOneNil bool
}

NilCountOptions sets various options for the NilCount function.

type Options

type Options struct {

	// Don't apply lock.
	DontLock bool
}

Options sets various options.

type OrderedMapIntFloat64

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

OrderedMapIntFloat64 is an ordered map[int]float64.

func NewOrderedMapIntFloat64

func NewOrderedMapIntFloat64(notOrdered ...bool) *OrderedMapIntFloat64

NewOrderedMapIntFloat64 will create a new OrderedMapIntFloat64. By default it will be ordered, but setting notOrdered to true will make it operate as a builtin map.

func (*OrderedMapIntFloat64) Delete

func (o *OrderedMapIntFloat64) Delete(key int)

Delete will remove the key from the OrderedMapIntFloat64. For performance reasons, ensure the key exists beforehand when in ordered mode.

func (*OrderedMapIntFloat64) Get

func (o *OrderedMapIntFloat64) Get(key int) (float64, bool)

Get will return the value of the key. If it doesn't exist, it will return false for the second return value.

func (*OrderedMapIntFloat64) Set

func (o *OrderedMapIntFloat64) Set(key int, val float64)

Set will set a key and value pair. It will overwrite an existing pair if it exists already.

func (*OrderedMapIntFloat64) ValuesIterator

func (o *OrderedMapIntFloat64) ValuesIterator() func() (*int, float64)

ValuesIterator is used to iterate through the values of OrderedMapIntFloat64.

type OrderedMapIntMixed

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

OrderedMapIntMixed is an ordered map[int]interface{}.

func NewOrderedMapIntMixed

func NewOrderedMapIntMixed(notOrdered ...bool) *OrderedMapIntMixed

NewOrderedMapIntMixed will create a new OrderedMapIntMixed. By default it will be ordered, but setting notOrdered to true will make it operate as a builtin map.

func (*OrderedMapIntMixed) Delete

func (o *OrderedMapIntMixed) Delete(key int)

Delete will remove the key from the OrderedMapIntMixed. For performance reasons, ensure the key exists beforehand when in ordered mode.

func (*OrderedMapIntMixed) Get

func (o *OrderedMapIntMixed) Get(key int) (interface{}, bool)

Get will return the value of the key. If it doesn't exist, it will return false for the second return value.

func (*OrderedMapIntMixed) Set

func (o *OrderedMapIntMixed) Set(key int, val interface{})

Set will set a key and value pair. It will overwrite an existing pair if it exists already.

func (*OrderedMapIntMixed) ValuesIterator

func (o *OrderedMapIntMixed) ValuesIterator() func() (*int, interface{})

ValuesIterator is used to iterate through the values of OrderedMapIntMixed.

type Rander

type Rander interface {

	// Rand returns a randomly generated float64.
	Rand() float64
}

Rander is an interface for generating random float64.

See: https://godoc.org/golang.org/x/exp/rand for a random generator source. See: https://godoc.org/gonum.org/v1/gonum/stat/distuv for various random distributions.

type Range

type Range struct {
	Start *int
	End   *int
}

Range is used to specify a range. Both Start and End are inclusive. A nil value means no limit, so a Start of nil means 0 and an End of nil means no limit. The End value must always be equal to or larger than Start. Negative values are acceptable. A value of -2 means the second last row.

func IntsToRanges

func IntsToRanges(ints []int) []Range

IntsToRanges will convert an already (ascending) ordered list of ints to a slice of Ranges.

Example:

import "sort"
ints := []int{2,4,5,6,8,10,11,45,46}
sort.Ints(ints)

fmt.Println(IntsToRanges(ints))
// Output: R{2,2}, R{4,6}, R{8,8}, R{10,11}, R{45,46}

func RangeFinite

func RangeFinite(start int, end ...int) Range

RangeFinite returns a Range that has a finite span.

func (*Range) Limits

func (r *Range) Limits(length int) (s int, e int, _ error)

Limits is used to return the start and end limits of a Range object for a given Dataframe or Series with length number of rows.

func (*Range) NRows

func (r *Range) NRows(length ...int) (int, error)

NRows returns the number of rows contained by Range. If End is nil, then length must be provided.

func (Range) String

func (r Range) String() string

String implements Stringer interface.

type RowError

type RowError struct {
	Row int
	Err error
}

RowError signifies that a particular row contained or generated an error.

func (*RowError) Error

func (re *RowError) Error() string

Error implements the error interface.

func (*RowError) Unwrap

func (re *RowError) Unwrap() error

Unwrap implements the Wrapper interface.

type Series

type Series interface {

	// Name returns the series name.
	Name(opts ...Options) string

	// Rename renames the series.
	Rename(n string, opts ...Options)

	// Type returns the type of data the series holds.
	Type() string

	// NRows returns how many rows the series contains.
	NRows(opts ...Options) int

	// Value returns the value of a particular row.
	// The return value could be nil or the concrete type
	// the data type held by the series.
	// Pointers are never returned.
	Value(row int, opts ...Options) interface{}

	// ValueString returns a string representation of a
	// particular row. The string representation is defined
	// by the function set in SetValueToStringFormatter.
	// By default, a nil value is returned as "NaN".
	ValueString(row int, opts ...Options) string

	// Prepend is used to set a value to the beginning of the
	// series. val can be a concrete data type or nil. Nil
	// represents the absence of a value.
	Prepend(val interface{}, opts ...Options)

	// Append is used to set a value to the end of the series.
	// val can be a concrete data type or nil. Nil represents
	// the absence of a value.
	Append(val interface{}, opts ...Options) int

	// Insert is used to set a value at an arbitrary row in
	// the series. All existing values from that row onwards
	// are shifted by 1. val can be a concrete data type or nil.
	// Nil represents the absence of a value.
	Insert(row int, val interface{}, opts ...Options)

	// Remove is used to delete the value of a particular row.
	Remove(row int, opts ...Options)

	// Reset is used clear all data contained in the Series.
	Reset(opts ...Options)

	// ValuesIterator will return a function that can be used to iterate through all the values.
	ValuesIterator(opts ...ValuesOptions) func() (*int, interface{}, int)

	// Update is used to update the value of a particular row.
	// val can be a concrete data type or nil. Nil represents
	// the absence of a value.
	Update(row int, val interface{}, opts ...Options)

	// SetValueToStringFormatter is used to set a function
	// to convert the value of a particular row to a string
	// representation.
	SetValueToStringFormatter(f ValueToStringFormatter)

	// Sort will sort the series.
	// It will return true if sorting was completed or false when the context is canceled.
	Sort(ctx context.Context, opts ...SortOptions) (completed bool)

	// IsEqualFunc returns true if a is equal to b.
	IsEqualFunc(a, b interface{}) bool

	// IsLessThanFunc returns true if a is less than b.
	IsLessThanFunc(a, b interface{}) bool

	// Swap is used to swap 2 values based on their row position.
	Swap(row1, row2 int, opts ...Options)

	// Lock will lock the Series allowing you to directly manipulate
	// the underlying slice with confidence.
	Lock()

	// Unlock will unlock the Series that was previously locked.
	Unlock()

	// Copy will create a new copy of the series.
	// It is recommended that you lock the Series before attempting
	// to Copy.
	Copy(r ...Range) Series

	// ContainsNil will return whether or not the series contains any nil values.
	ContainsNil(opts ...Options) bool

	// NilCount will return how many nil values are in the series.
	NilCount(opts ...NilCountOptions) (int, error)

	// IsEqual returns true if s2's values are equal to s.
	IsEqual(ctx context.Context, s2 Series, opts ...IsEqualOptions) (bool, error)
}

Series is a collection of data that could be of any type. It is usually used with DataFrame.

type SeriesFloat64

type SeriesFloat64 struct {

	// Values is exported to better improve interoperability with the gonum package.
	//
	// See: https://godoc.org/gonum.org/v1/gonum
	//
	// WARNING: Do not modify directly.
	Values []float64
	// contains filtered or unexported fields
}

SeriesFloat64 is used for series containing float64 data.

func NewSeriesFloat64

func NewSeriesFloat64(name string, init *SeriesInit, vals ...interface{}) *SeriesFloat64

NewSeriesFloat64 creates a new series with the underlying type as float64.

func (*SeriesFloat64) Append

func (s *SeriesFloat64) Append(val interface{}, opts ...Options) int

Append is used to set a value to the end of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesFloat64) AsciiGraph

func (s *SeriesFloat64) AsciiGraph(opts ...AsciiGraphOptions) string

AsciiGraph will produce a simple ascii based graph of the data. The function will panic if the range R is invalid.

func (*SeriesFloat64) ContainsNil

func (s *SeriesFloat64) ContainsNil(opts ...Options) bool

ContainsNil will return whether or not the series contains any nil values.

func (*SeriesFloat64) Copy

func (s *SeriesFloat64) Copy(r ...Range) Series

Copy will create a new copy of the series. It is recommended that you lock the Series before attempting to Copy.

func (*SeriesFloat64) FillRand

func (s *SeriesFloat64) FillRand(src rand.Source, probNil float64, rander Rander, opts ...FillRandOptions)

FillRand will fill a Series with random data. probNil is a value between between 0 and 1 which determines if a row is given a nil value.

func (*SeriesFloat64) Insert

func (s *SeriesFloat64) Insert(row int, val interface{}, opts ...Options)

Insert is used to set a value at an arbitrary row in the series. All existing values from that row onwards are shifted by 1. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesFloat64) IsEqual

func (s *SeriesFloat64) IsEqual(ctx context.Context, s2 Series, opts ...IsEqualOptions) (bool, error)

IsEqual returns true if s2's values are equal to s.

func (*SeriesFloat64) IsEqualFunc

func (s *SeriesFloat64) IsEqualFunc(a, b interface{}) bool

IsEqualFunc returns true if a is equal to b.

func (*SeriesFloat64) IsLessThanFunc

func (s *SeriesFloat64) IsLessThanFunc(a, b interface{}) bool

IsLessThanFunc returns true if a is less than b.

func (*SeriesFloat64) Lock

func (s *SeriesFloat64) Lock()

Lock will lock the Series allowing you to directly manipulate the underlying slice with confidence.

func (*SeriesFloat64) Mean

func (s *SeriesFloat64) Mean(ctx context.Context) (float64, error)

Mean returns the mean. All non-nil values are ignored.

func (*SeriesFloat64) NRows

func (s *SeriesFloat64) NRows(opts ...Options) int

NRows returns how many rows the series contains.

func (*SeriesFloat64) Name

func (s *SeriesFloat64) Name(opts ...Options) string

Name returns the series name.

func (*SeriesFloat64) NewSeries

func (s *SeriesFloat64) NewSeries(name string, init *SeriesInit) Series

NewSeries creates a new initialized SeriesFloat64.

func (*SeriesFloat64) NilCount

func (s *SeriesFloat64) NilCount(opts ...NilCountOptions) (int, error)

NilCount will return how many nil values are in the series.

func (*SeriesFloat64) Prepend

func (s *SeriesFloat64) Prepend(val interface{}, opts ...Options)

Prepend is used to set a value to the beginning of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesFloat64) Remove

func (s *SeriesFloat64) Remove(row int, opts ...Options)

Remove is used to delete the value of a particular row.

func (*SeriesFloat64) Rename

func (s *SeriesFloat64) Rename(n string, opts ...Options)

Rename renames the series.

func (*SeriesFloat64) Reset

func (s *SeriesFloat64) Reset(opts ...Options)

Reset is used clear all data contained in the Series.

func (*SeriesFloat64) SetValueToStringFormatter

func (s *SeriesFloat64) SetValueToStringFormatter(f ValueToStringFormatter)

SetValueToStringFormatter is used to set a function to convert the value of a particular row to a string representation.

func (*SeriesFloat64) Sort

func (s *SeriesFloat64) Sort(ctx context.Context, opts ...SortOptions) (completed bool)

Sort will sort the series. It will return true if sorting was completed or false when the context is canceled.

func (*SeriesFloat64) String

func (s *SeriesFloat64) String() string

String implements the fmt.Stringer interface. It does not lock the Series.

func (*SeriesFloat64) Sum

func (s *SeriesFloat64) Sum(ctx context.Context) (float64, error)

Sum returns the sum of all non-nil values. If all values are nil, a NaN is returned. If opposing infinites are found, a NaN is also returned

func (*SeriesFloat64) Swap

func (s *SeriesFloat64) Swap(row1, row2 int, opts ...Options)

Swap is used to swap 2 values based on their row position.

func (*SeriesFloat64) Table

func (s *SeriesFloat64) Table(opts ...TableOptions) string

Table will produce the Series in a table.

func (*SeriesFloat64) ToSeriesFloat64

func (s *SeriesFloat64) ToSeriesFloat64(ctx context.Context, removeNil bool, conv ...func(interface{}) (float64, error)) (*SeriesFloat64, error)

ToSeriesFloat64 will create a new SeriesFloat64. If removeNil is false, the function will simply create a copy. In the current implementation, conv is ignored. The operation does not lock the Series.

func (*SeriesFloat64) ToSeriesMixed

func (s *SeriesFloat64) ToSeriesMixed(ctx context.Context, removeNil bool, conv ...func(interface{}) (interface{}, error)) (*SeriesMixed, error)

ToSeriesMixed will convert the Series to a SeriesMIxed. The operation does not lock the Series.

func (*SeriesFloat64) ToSeriesString

func (s *SeriesFloat64) ToSeriesString(ctx context.Context, removeNil bool, conv ...func(interface{}) (*string, error)) (*SeriesString, error)

ToSeriesString will convert the Series to a SeriesString. The operation does not lock the Series.

func (*SeriesFloat64) Type

func (s *SeriesFloat64) Type() string

Type returns the type of data the series holds.

func (*SeriesFloat64) Unlock

func (s *SeriesFloat64) Unlock()

Unlock will unlock the Series that was previously locked.

func (*SeriesFloat64) Update

func (s *SeriesFloat64) Update(row int, val interface{}, opts ...Options)

Update is used to update the value of a particular row. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesFloat64) Value

func (s *SeriesFloat64) Value(row int, opts ...Options) interface{}

Value returns the value of a particular row. The return value could be nil or the concrete type the data type held by the series. Pointers are never returned.

func (*SeriesFloat64) ValueString

func (s *SeriesFloat64) ValueString(row int, opts ...Options) string

ValueString returns a string representation of a particular row. The string representation is defined by the function set in SetValueToStringFormatter. By default, a nil value is returned as "NaN".

func (*SeriesFloat64) ValuesIterator

func (s *SeriesFloat64) ValuesIterator(opts ...ValuesOptions) func() (*int, interface{}, int)

ValuesIterator will return a function that can be used to iterate through all the values.

type SeriesGeneric

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

SeriesGeneric is a series of data where the contained data can be of any type. Only concrete data types can be used.

func NewSeriesGeneric

func NewSeriesGeneric(name string, concreteType interface{}, init *SeriesInit, vals ...interface{}) *SeriesGeneric

NewSeriesGeneric creates a new generic series.

func (*SeriesGeneric) Append

func (s *SeriesGeneric) Append(val interface{}, opts ...Options) int

Append is used to set a value to the end of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesGeneric) ContainsNil

func (s *SeriesGeneric) ContainsNil(opts ...Options) bool

ContainsNil will return whether or not the series contains any nil values.

func (*SeriesGeneric) Copy

func (s *SeriesGeneric) Copy(r ...Range) Series

Copy will create a new copy of the series. It is recommended that you lock the Series before attempting to Copy.

func (*SeriesGeneric) Insert

func (s *SeriesGeneric) Insert(row int, val interface{}, opts ...Options)

Insert is used to set a value at an arbitrary row in the series. All existing values from that row onwards are shifted by 1. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesGeneric) IsEqual

func (s *SeriesGeneric) IsEqual(ctx context.Context, s2 Series, opts ...IsEqualOptions) (bool, error)

IsEqual returns true if s2's values are equal to s.

func (*SeriesGeneric) IsEqualFunc

func (s *SeriesGeneric) IsEqualFunc(a, b interface{}) bool

IsEqualFunc returns true if a is equal to b.

func (*SeriesGeneric) IsLessThanFunc

func (s *SeriesGeneric) IsLessThanFunc(a, b interface{}) bool

IsLessThanFunc returns true if a is less than b.

func (*SeriesGeneric) Lock

func (s *SeriesGeneric) Lock()

Lock will lock the Series allowing you to directly manipulate the underlying slice with confidence.

func (*SeriesGeneric) NRows

func (s *SeriesGeneric) NRows(opts ...Options) int

NRows returns how many rows the series contains.

func (*SeriesGeneric) Name

func (s *SeriesGeneric) Name(opts ...Options) string

Name returns the series name.

func (*SeriesGeneric) NilCount

func (s *SeriesGeneric) NilCount(opts ...NilCountOptions) (int, error)

NilCount will return how many nil values are in the series.

func (*SeriesGeneric) Prepend

func (s *SeriesGeneric) Prepend(val interface{}, opts ...Options)

Prepend is used to set a value to the beginning of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesGeneric) Remove

func (s *SeriesGeneric) Remove(row int, opts ...Options)

Remove is used to delete the value of a particular row.

func (*SeriesGeneric) Rename

func (s *SeriesGeneric) Rename(n string, opts ...Options)

Rename renames the series.

func (*SeriesGeneric) Reset

func (s *SeriesGeneric) Reset(opts ...Options)

Reset is used clear all data contained in the Series.

func (*SeriesGeneric) SetIsEqualFunc

func (s *SeriesGeneric) SetIsEqualFunc(f IsEqualFunc)

SetIsEqualFunc sets a function which can be used to determine if 2 values in the series are equal.

func (*SeriesGeneric) SetIsLessThanFunc

func (s *SeriesGeneric) SetIsLessThanFunc(f IsLessThanFunc)

SetIsLessThanFunc sets a function which can be used to determine if a value is less than another in the series.

func (*SeriesGeneric) SetValueToStringFormatter

func (s *SeriesGeneric) SetValueToStringFormatter(f ValueToStringFormatter)

SetValueToStringFormatter is used to set a function to convert the value of a particular row to a string representation.

func (*SeriesGeneric) Sort

func (s *SeriesGeneric) Sort(ctx context.Context, opts ...SortOptions) (completed bool)

Sort will sort the series. It will return true if sorting was completed or false when the context is canceled.

func (*SeriesGeneric) String

func (s *SeriesGeneric) String() string

String implements the fmt.Stringer interface. It does not lock the Series.

func (*SeriesGeneric) Swap

func (s *SeriesGeneric) Swap(row1, row2 int, opts ...Options)

Swap is used to swap 2 values based on their row position.

func (*SeriesGeneric) Table

func (s *SeriesGeneric) Table(opts ...TableOptions) string

Table will produce the Series in a table.

func (*SeriesGeneric) ToSeriesMixed

func (s *SeriesGeneric) ToSeriesMixed(ctx context.Context, removeNil bool, conv ...func(interface{}) (interface{}, error)) (*SeriesMixed, error)

ToSeriesMixed will convert the Series to a SeriesMIxed. The operation does not lock the Series.

func (*SeriesGeneric) Type

func (s *SeriesGeneric) Type() string

Type returns the type of data the series holds.

func (*SeriesGeneric) Unlock

func (s *SeriesGeneric) Unlock()

Unlock will unlock the Series that was previously locked.

func (*SeriesGeneric) Update

func (s *SeriesGeneric) Update(row int, val interface{}, opts ...Options)

Update is used to update the value of a particular row. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesGeneric) Value

func (s *SeriesGeneric) Value(row int, opts ...Options) interface{}

Value returns the value of a particular row. The return value could be nil or the concrete type the data type held by the series. Pointers are never returned.

func (*SeriesGeneric) ValueString

func (s *SeriesGeneric) ValueString(row int, opts ...Options) string

ValueString returns a string representation of a particular row. The string representation is defined by the function set in SetValueToStringFormatter. By default, a nil value is returned as "NaN".

func (*SeriesGeneric) ValuesIterator

func (s *SeriesGeneric) ValuesIterator(opts ...ValuesOptions) func() (*int, interface{}, int)

ValuesIterator will return a function that can be used to iterate through all the values.

type SeriesInit

type SeriesInit struct {
	// Prefill the series with nil ("NaN") with
	// Size number of rows.
	Size int
	// How much memory to preallocate.
	// If you know the size of the series in advance,
	// it is better to preallocate the capacity of the
	// underlying slice.
	Capacity int
}

SeriesInit is used to configure the series when it is initialized

type SeriesInt64

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

SeriesInt64 is used for series containing int64 data.

func NewSeriesInt64

func NewSeriesInt64(name string, init *SeriesInit, vals ...interface{}) *SeriesInt64

NewSeriesInt64 creates a new series with the underlying type as int64.

func (*SeriesInt64) Append

func (s *SeriesInt64) Append(val interface{}, opts ...Options) int

Append is used to set a value to the end of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesInt64) ContainsNil

func (s *SeriesInt64) ContainsNil(opts ...Options) bool

ContainsNil will return whether or not the series contains any nil values.

func (*SeriesInt64) Copy

func (s *SeriesInt64) Copy(r ...Range) Series

Copy will create a new copy of the series. It is recommended that you lock the Series before attempting to Copy.

func (*SeriesInt64) FillRand

func (s *SeriesInt64) FillRand(src rand.Source, probNil float64, rander Rander, opts ...FillRandOptions)

FillRand will fill a Series with random data. probNil is a value between between 0 and 1 which determines if a row is given a nil value.

func (*SeriesInt64) Insert

func (s *SeriesInt64) Insert(row int, val interface{}, opts ...Options)

Insert is used to set a value at an arbitrary row in the series. All existing values from that row onwards are shifted by 1. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesInt64) IsEqual

func (s *SeriesInt64) IsEqual(ctx context.Context, s2 Series, opts ...IsEqualOptions) (bool, error)

IsEqual returns true if s2's values are equal to s.

func (*SeriesInt64) IsEqualFunc

func (s *SeriesInt64) IsEqualFunc(a, b interface{}) bool

IsEqualFunc returns true if a is equal to b.

func (*SeriesInt64) IsLessThanFunc

func (s *SeriesInt64) IsLessThanFunc(a, b interface{}) bool

IsLessThanFunc returns true if a is less than b.

func (*SeriesInt64) Lock

func (s *SeriesInt64) Lock()

Lock will lock the Series allowing you to directly manipulate the underlying slice with confidence.

func (*SeriesInt64) Mean

func (s *SeriesInt64) Mean(ctx context.Context) (float64, error)

Mean returns the mean. All non-nil values are ignored.

func (*SeriesInt64) NRows

func (s *SeriesInt64) NRows(opts ...Options) int

NRows returns how many rows the series contains.

func (*SeriesInt64) Name

func (s *SeriesInt64) Name(opts ...Options) string

Name returns the series name.

func (*SeriesInt64) NewSeries

func (s *SeriesInt64) NewSeries(name string, init *SeriesInit) Series

NewSeries creates a new initialized SeriesInt64.

func (*SeriesInt64) NilCount

func (s *SeriesInt64) NilCount(opts ...NilCountOptions) (int, error)

NilCount will return how many nil values are in the series.

func (*SeriesInt64) Prepend

func (s *SeriesInt64) Prepend(val interface{}, opts ...Options)

Prepend is used to set a value to the beginning of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesInt64) Remove

func (s *SeriesInt64) Remove(row int, opts ...Options)

Remove is used to delete the value of a particular row.

func (*SeriesInt64) Rename

func (s *SeriesInt64) Rename(n string, opts ...Options)

Rename renames the series.

func (*SeriesInt64) Reset

func (s *SeriesInt64) Reset(opts ...Options)

Reset is used clear all data contained in the Series.

func (*SeriesInt64) SetValueToStringFormatter

func (s *SeriesInt64) SetValueToStringFormatter(f ValueToStringFormatter)

SetValueToStringFormatter is used to set a function to convert the value of a particular row to a string representation.

func (*SeriesInt64) Sort

func (s *SeriesInt64) Sort(ctx context.Context, opts ...SortOptions) (completed bool)

Sort will sort the series. It will return true if sorting was completed or false when the context is canceled.

func (*SeriesInt64) String

func (s *SeriesInt64) String() string

String implements the fmt.Stringer interface. It does not lock the Series.

func (*SeriesInt64) Sum

func (s *SeriesInt64) Sum(ctx context.Context) (float64, error)

Sum returns the sum of all non-nil values. If all values are nil, a NaN is returned.

func (*SeriesInt64) Swap

func (s *SeriesInt64) Swap(row1, row2 int, opts ...Options)

Swap is used to swap 2 values based on their row position.

func (*SeriesInt64) Table

func (s *SeriesInt64) Table(opts ...TableOptions) string

Table will produce the Series in a table.

func (*SeriesInt64) ToSeriesFloat64

func (s *SeriesInt64) ToSeriesFloat64(ctx context.Context, removeNil bool, conv ...func(interface{}) (float64, error)) (*SeriesFloat64, error)

ToSeriesFloat64 will convert the Series to a SeriesFloat64. The operation does not lock the Series.

func (*SeriesInt64) ToSeriesMixed

func (s *SeriesInt64) ToSeriesMixed(ctx context.Context, removeNil bool, conv ...func(interface{}) (interface{}, error)) (*SeriesMixed, error)

ToSeriesMixed will convert the Series to a SeriesMIxed. The operation does not lock the Series.

func (*SeriesInt64) ToSeriesString

func (s *SeriesInt64) ToSeriesString(ctx context.Context, removeNil bool, conv ...func(interface{}) (*string, error)) (*SeriesString, error)

ToSeriesString will convert the Series to a SeriesString. The operation does not lock the Series.

func (*SeriesInt64) Type

func (s *SeriesInt64) Type() string

Type returns the type of data the series holds.

func (*SeriesInt64) Unlock

func (s *SeriesInt64) Unlock()

Unlock will unlock the Series that was previously locked.

func (*SeriesInt64) Update

func (s *SeriesInt64) Update(row int, val interface{}, opts ...Options)

Update is used to update the value of a particular row. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesInt64) Value

func (s *SeriesInt64) Value(row int, opts ...Options) interface{}

Value returns the value of a particular row. The return value could be nil or the concrete type the data type held by the series. Pointers are never returned.

func (*SeriesInt64) ValueString

func (s *SeriesInt64) ValueString(row int, opts ...Options) string

ValueString returns a string representation of a particular row. The string representation is defined by the function set in SetValueToStringFormatter. By default, a nil value is returned as "NaN".

func (*SeriesInt64) ValuesIterator

func (s *SeriesInt64) ValuesIterator(opts ...ValuesOptions) func() (*int, interface{}, int)

ValuesIterator will return a function that can be used to iterate through all the values.

type SeriesMixed

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

SeriesMixed is used for series containing mixed data.

func NewSeriesMixed

func NewSeriesMixed(name string, init *SeriesInit, vals ...interface{}) *SeriesMixed

NewSeriesMixed creates a new series with the underlying type as interface{}.

func (*SeriesMixed) Append

func (s *SeriesMixed) Append(val interface{}, opts ...Options) int

Append is used to set a value to the end of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesMixed) ContainsNil

func (s *SeriesMixed) ContainsNil(opts ...Options) bool

ContainsNil will return whether or not the series contains any nil values.

func (*SeriesMixed) Copy

func (s *SeriesMixed) Copy(r ...Range) Series

Copy will create a new copy of the series. It is recommended that you lock the Series before attempting to Copy.

func (*SeriesMixed) FillRand

func (s *SeriesMixed) FillRand(src rand.Source, probNil float64, rander Rander, opts ...FillRandOptions)

FillRand will fill a Series with random data. probNil is a value between between 0 and 1 which determines if a row is given a nil value.

func (*SeriesMixed) Insert

func (s *SeriesMixed) Insert(row int, val interface{}, opts ...Options)

Insert is used to set a value at an arbitrary row in the series. All existing values from that row onwards are shifted by 1. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesMixed) IsEqual

func (s *SeriesMixed) IsEqual(ctx context.Context, s2 Series, opts ...IsEqualOptions) (bool, error)

IsEqual returns true if s2's values are equal to s.

func (*SeriesMixed) IsEqualFunc

func (s *SeriesMixed) IsEqualFunc(a, b interface{}) bool

IsEqualFunc returns true if a is equal to b.

func (*SeriesMixed) IsLessThanFunc

func (s *SeriesMixed) IsLessThanFunc(a, b interface{}) bool

IsLessThanFunc returns true if a is less than b.

func (*SeriesMixed) Lock

func (s *SeriesMixed) Lock()

Lock will lock the Series allowing you to directly manipulate the underlying slice with confidence.

func (*SeriesMixed) NRows

func (s *SeriesMixed) NRows(opts ...Options) int

NRows returns how many rows the series contains.

func (*SeriesMixed) Name

func (s *SeriesMixed) Name(opts ...Options) string

Name returns the series name.

func (*SeriesMixed) NewSeries

func (s *SeriesMixed) NewSeries(name string, init *SeriesInit) Series

NewSeries creates a new initialized SeriesMixed.

func (*SeriesMixed) NilCount

func (s *SeriesMixed) NilCount(opts ...NilCountOptions) (int, error)

NilCount will return how many nil values are in the series.

func (*SeriesMixed) Prepend

func (s *SeriesMixed) Prepend(val interface{}, opts ...Options)

Prepend is used to set a value to the beginning of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesMixed) Remove

func (s *SeriesMixed) Remove(row int, opts ...Options)

Remove is used to delete the value of a particular row.

func (*SeriesMixed) Rename

func (s *SeriesMixed) Rename(n string, opts ...Options)

Rename renames the series.

func (*SeriesMixed) Reset

func (s *SeriesMixed) Reset(opts ...Options)

Reset is used clear all data contained in the Series.

func (*SeriesMixed) SetIsEqualFunc

func (s *SeriesMixed) SetIsEqualFunc(f IsEqualFunc)

SetIsEqualFunc sets a function which can be used to determine if 2 values in the series are equal.

func (*SeriesMixed) SetIsLessThanFunc

func (s *SeriesMixed) SetIsLessThanFunc(f IsLessThanFunc)

SetIsLessThanFunc sets a function which can be used to determine if a value is less than another in the series.

func (*SeriesMixed) SetValueToStringFormatter

func (s *SeriesMixed) SetValueToStringFormatter(f ValueToStringFormatter)

SetValueToStringFormatter is used to set a function to convert the value of a particular row to a string representation.

func (*SeriesMixed) Sort

func (s *SeriesMixed) Sort(ctx context.Context, opts ...SortOptions) (completed bool)

Sort will sort the series. It will return true if sorting was completed or false when the context is canceled.

func (*SeriesMixed) String

func (s *SeriesMixed) String() string

String implements the fmt.Stringer interface. It does not lock the Series.

func (*SeriesMixed) Swap

func (s *SeriesMixed) Swap(row1, row2 int, opts ...Options)

Swap is used to swap 2 values based on their row position.

func (*SeriesMixed) Table

func (s *SeriesMixed) Table(opts ...TableOptions) string

Table will produce the Series in a table.

func (*SeriesMixed) ToSeriesString

func (s *SeriesMixed) ToSeriesString(ctx context.Context, removeNil bool, conv ...func(interface{}) (*string, error)) (*SeriesString, error)

ToSeriesString will convert the Series to a SeriesString. The operation does not lock the Series.

func (*SeriesMixed) Type

func (s *SeriesMixed) Type() string

Type returns the type of data the series holds.

func (*SeriesMixed) Unlock

func (s *SeriesMixed) Unlock()

Unlock will unlock the Series that was previously locked.

func (*SeriesMixed) Update

func (s *SeriesMixed) Update(row int, val interface{}, opts ...Options)

Update is used to update the value of a particular row. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesMixed) Value

func (s *SeriesMixed) Value(row int, opts ...Options) interface{}

Value returns the value of a particular row. The return value could be nil or the concrete type the data type held by the series. Pointers are never returned.

func (*SeriesMixed) ValueString

func (s *SeriesMixed) ValueString(row int, opts ...Options) string

ValueString returns a string representation of a particular row. The string representation is defined by the function set in SetValueToStringFormatter. By default, a nil value is returned as "NaN".

func (*SeriesMixed) ValuesIterator

func (s *SeriesMixed) ValuesIterator(opts ...ValuesOptions) func() (*int, interface{}, int)

ValuesIterator will return a function that can be used to iterate through all the values.

type SeriesReturnOpt

type SeriesReturnOpt uint8

SeriesReturnOpt is used to control if Row/Values method returns the series index, series name or both as map keys.

const (
	// SeriesIdx forces the series' index to be returned as a map key.
	SeriesIdx SeriesReturnOpt = 1 << iota
	// SeriesName forces the series' name to be returned as a map key.
	SeriesName
)

type SeriesString

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

SeriesString is used for series containing string data.

func NewSeriesString

func NewSeriesString(name string, init *SeriesInit, vals ...interface{}) *SeriesString

NewSeriesString creates a new series with the underlying type as string.

func (*SeriesString) Append

func (s *SeriesString) Append(val interface{}, opts ...Options) int

Append is used to set a value to the end of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesString) ContainsNil

func (s *SeriesString) ContainsNil(opts ...Options) bool

ContainsNil will return whether or not the series contains any nil values.

func (*SeriesString) Copy

func (s *SeriesString) Copy(r ...Range) Series

Copy will create a new copy of the series. It is recommended that you lock the Series before attempting to Copy.

func (*SeriesString) FillRand

func (s *SeriesString) FillRand(src rand.Source, probNil float64, rander Rander, opts ...FillRandOptions)

FillRand will fill a Series with random data. probNil is a value between between 0 and 1 which determines if a row is given a nil value.

func (*SeriesString) Insert

func (s *SeriesString) Insert(row int, val interface{}, opts ...Options)

Insert is used to set a value at an arbitrary row in the series. All existing values from that row onwards are shifted by 1. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesString) IsEqual

func (s *SeriesString) IsEqual(ctx context.Context, s2 Series, opts ...IsEqualOptions) (bool, error)

IsEqual returns true if s2's values are equal to s.

func (*SeriesString) IsEqualFunc

func (s *SeriesString) IsEqualFunc(a, b interface{}) bool

IsEqualFunc returns true if a is equal to b.

func (*SeriesString) IsLessThanFunc

func (s *SeriesString) IsLessThanFunc(a, b interface{}) bool

IsLessThanFunc returns true if a is less than b.

func (*SeriesString) Lock

func (s *SeriesString) Lock()

Lock will lock the Series allowing you to directly manipulate the underlying slice with confidence.

func (*SeriesString) NRows

func (s *SeriesString) NRows(opts ...Options) int

NRows returns how many rows the series contains.

func (*SeriesString) Name

func (s *SeriesString) Name(opts ...Options) string

Name returns the series name.

func (*SeriesString) NewSeries

func (s *SeriesString) NewSeries(name string, init *SeriesInit) Series

NewSeries creates a new initialized SeriesString.

func (*SeriesString) NilCount

func (s *SeriesString) NilCount(opts ...NilCountOptions) (int, error)

NilCount will return how many nil values are in the series.

func (*SeriesString) Prepend

func (s *SeriesString) Prepend(val interface{}, opts ...Options)

Prepend is used to set a value to the beginning of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesString) Remove

func (s *SeriesString) Remove(row int, opts ...Options)

Remove is used to delete the value of a particular row.

func (*SeriesString) Rename

func (s *SeriesString) Rename(n string, opts ...Options)

Rename renames the series.

func (*SeriesString) Reset

func (s *SeriesString) Reset(opts ...Options)

Reset is used clear all data contained in the Series.

func (*SeriesString) SetValueToStringFormatter

func (s *SeriesString) SetValueToStringFormatter(f ValueToStringFormatter)

SetValueToStringFormatter is used to set a function to convert the value of a particular row to a string representation.

func (*SeriesString) Sort

func (s *SeriesString) Sort(ctx context.Context, opts ...SortOptions) (completed bool)

Sort will sort the series. It will return true if sorting was completed or false when the context is canceled.

func (*SeriesString) String

func (s *SeriesString) String() string

String implements the fmt.Stringer interface. It does not lock the Series.

func (*SeriesString) Swap

func (s *SeriesString) Swap(row1, row2 int, opts ...Options)

Swap is used to swap 2 values based on their row position.

func (*SeriesString) Table

func (s *SeriesString) Table(opts ...TableOptions) string

Table will produce the Series in a table.

func (*SeriesString) ToSeriesFloat64

func (s *SeriesString) ToSeriesFloat64(ctx context.Context, removeNil bool, conv ...func(interface{}) (float64, error)) (*SeriesFloat64, error)

ToSeriesFloat64 will convert the Series to a SeriesFloat64. The operation does not lock the Series.

func (*SeriesString) ToSeriesInt64

func (s *SeriesString) ToSeriesInt64(ctx context.Context, removeNil bool, conv ...func(interface{}) (*int64, error)) (*SeriesInt64, error)

ToSeriesInt64 will convert the Series to a SeriesInt64. The operation does not lock the Series.

func (*SeriesString) ToSeriesMixed

func (s *SeriesString) ToSeriesMixed(ctx context.Context, removeNil bool, conv ...func(interface{}) (interface{}, error)) (*SeriesMixed, error)

ToSeriesMixed will convert the Series to a SeriesMIxed. The operation does not lock the Series.

func (*SeriesString) Type

func (s *SeriesString) Type() string

Type returns the type of data the series holds.

func (*SeriesString) Unlock

func (s *SeriesString) Unlock()

Unlock will unlock the Series that was previously locked.

func (*SeriesString) Update

func (s *SeriesString) Update(row int, val interface{}, opts ...Options)

Update is used to update the value of a particular row. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesString) Value

func (s *SeriesString) Value(row int, opts ...Options) interface{}

Value returns the value of a particular row. The return value could be nil or the concrete type the data type held by the series. Pointers are never returned.

func (*SeriesString) ValueString

func (s *SeriesString) ValueString(row int, opts ...Options) string

ValueString returns a string representation of a particular row. The string representation is defined by the function set in SetValueToStringFormatter. By default, a nil value is returned as "NaN".

func (*SeriesString) ValuesIterator

func (s *SeriesString) ValuesIterator(opts ...ValuesOptions) func() (*int, interface{}, int)

ValuesIterator will return a function that can be used to iterate through all the values.

type SeriesTime

type SeriesTime struct {

	// Layout is for internal use only at the moment. Do not use.
	//
	// See: https://golang.org/pkg/time/#Parse
	Layout string

	// Values is exported to better improve interoperability with various sub-packages.
	//
	// WARNING: Do not modify directly.
	Values []*time.Time
	// contains filtered or unexported fields
}

SeriesTime is used for series containing time.Time data.

func NewSeriesTime

func NewSeriesTime(name string, init *SeriesInit, vals ...interface{}) *SeriesTime

NewSeriesTime creates a new series with the underlying type as time.Time.

func (*SeriesTime) Append

func (s *SeriesTime) Append(val interface{}, opts ...Options) int

Append is used to set a value to the end of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesTime) ContainsNil

func (s *SeriesTime) ContainsNil(opts ...Options) bool

ContainsNil will return whether or not the series contains any nil values.

func (*SeriesTime) Copy

func (s *SeriesTime) Copy(r ...Range) Series

Copy will create a new copy of the series. It is recommended that you lock the Series before attempting to Copy.

func (*SeriesTime) FillRand

func (s *SeriesTime) FillRand(src rand.Source, probNil float64, rander Rander, opts ...FillRandOptions)

FillRand will fill a Series with random data. probNil is a value between between 0 and 1 which determines if a row is given a nil value.

func (*SeriesTime) Insert

func (s *SeriesTime) Insert(row int, val interface{}, opts ...Options)

Insert is used to set a value at an arbitrary row in the series. All existing values from that row onwards are shifted by 1. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesTime) IsEqual

func (s *SeriesTime) IsEqual(ctx context.Context, s2 Series, opts ...IsEqualOptions) (bool, error)

IsEqual returns true if s2's values are equal to s.

func (*SeriesTime) IsEqualFunc

func (s *SeriesTime) IsEqualFunc(a, b interface{}) bool

IsEqualFunc returns true if a is equal to b.

func (*SeriesTime) IsLessThanFunc

func (s *SeriesTime) IsLessThanFunc(a, b interface{}) bool

IsLessThanFunc returns true if a is less than b.

func (*SeriesTime) Lock

func (s *SeriesTime) Lock()

Lock will lock the Series allowing you to directly manipulate the underlying slice with confidence.

func (*SeriesTime) NRows

func (s *SeriesTime) NRows(opts ...Options) int

NRows returns how many rows the series contains.

func (*SeriesTime) Name

func (s *SeriesTime) Name(opts ...Options) string

Name returns the series name.

func (*SeriesTime) NewSeries

func (s *SeriesTime) NewSeries(name string, init *SeriesInit) Series

NewSeries creates a new initialized SeriesTime.

func (*SeriesTime) NilCount

func (s *SeriesTime) NilCount(opts ...NilCountOptions) (int, error)

NilCount will return how many nil values are in the series.

func (*SeriesTime) Prepend

func (s *SeriesTime) Prepend(val interface{}, opts ...Options)

Prepend is used to set a value to the beginning of the series. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesTime) Remove

func (s *SeriesTime) Remove(row int, opts ...Options)

Remove is used to delete the value of a particular row.

func (*SeriesTime) Rename

func (s *SeriesTime) Rename(n string, opts ...Options)

Rename renames the series.

func (*SeriesTime) Reset

func (s *SeriesTime) Reset(opts ...Options)

Reset is used clear all data contained in the Series.

func (*SeriesTime) SetValueToStringFormatter

func (s *SeriesTime) SetValueToStringFormatter(f ValueToStringFormatter)

SetValueToStringFormatter is used to set a function to convert the value of a particular row to a string representation.

func (*SeriesTime) Sort

func (s *SeriesTime) Sort(ctx context.Context, opts ...SortOptions) (completed bool)

Sort will sort the series. It will return true if sorting was completed or false when the context is canceled.

func (*SeriesTime) String

func (s *SeriesTime) String() string

String implements the fmt.Stringer interface. It does not lock the Series.

func (*SeriesTime) Swap

func (s *SeriesTime) Swap(row1, row2 int, opts ...Options)

Swap is used to swap 2 values based on their row position.

func (*SeriesTime) Table

func (s *SeriesTime) Table(opts ...TableOptions) string

Table will produce the Series in a table.

func (*SeriesTime) ToSeriesFloat64

func (s *SeriesTime) ToSeriesFloat64(ctx context.Context, removeNil bool, conv ...func(interface{}) (float64, error)) (*SeriesFloat64, error)

ToSeriesFloat64 will convert the Series to a SeriesFloat64. The time format is Unix seconds. The operation does not lock the Series.

func (*SeriesTime) ToSeriesInt64

func (s *SeriesTime) ToSeriesInt64(ctx context.Context, removeNil bool, conv ...func(interface{}) (*int64, error)) (*SeriesInt64, error)

ToSeriesInt64 will convert the Series to a SeriesInt64. The time format is Unix seconds. The operation does not lock the Series.

func (*SeriesTime) ToSeriesMixed

func (s *SeriesTime) ToSeriesMixed(ctx context.Context, removeNil bool, conv ...func(interface{}) (interface{}, error)) (*SeriesMixed, error)

ToSeriesMixed will convert the Series to a SeriesMIxed. The operation does not lock the Series.

func (*SeriesTime) Type

func (s *SeriesTime) Type() string

Type returns the type of data the series holds.

func (*SeriesTime) Unlock

func (s *SeriesTime) Unlock()

Unlock will unlock the Series that was previously locked.

func (*SeriesTime) Update

func (s *SeriesTime) Update(row int, val interface{}, opts ...Options)

Update is used to update the value of a particular row. val can be a concrete data type or nil. Nil represents the absence of a value.

func (*SeriesTime) Value

func (s *SeriesTime) Value(row int, opts ...Options) interface{}

Value returns the value of a particular row. The return value could be nil or the concrete type the data type held by the series. Pointers are never returned.

func (*SeriesTime) ValueString

func (s *SeriesTime) ValueString(row int, opts ...Options) string

ValueString returns a string representation of a particular row. The string representation is defined by the function set in SetValueToStringFormatter. By default, a nil value is returned as "NaN".

func (*SeriesTime) ValuesIterator

func (s *SeriesTime) ValuesIterator(opts ...ValuesOptions) func() (*int, interface{}, int)

ValuesIterator will return a function that can be used to iterate through all the values.

type SortKey

type SortKey struct {

	// Key can be an int (position of series) or string (name of series).
	Key interface{}

	// Desc can be set to sort in descending order.
	Desc bool
	// contains filtered or unexported fields
}

SortKey is the key to sort a Dataframe

type SortOptions

type SortOptions struct {

	// Stable can be set if the original order of equal items must be maintained.
	//
	// See: https://golang.org/pkg/sort/#Stable
	Stable bool

	// Desc can be set to sort in descending order. This option is ignored when applied to a Dataframe.
	// Only use it with a Series.
	Desc bool

	// DontLock can be set to true if the Series should not be locked.
	DontLock bool
}

SortOptions is used to configure the sort algorithm for a Dataframe or Series

type TableOptions

type TableOptions struct {

	// Series is used to display a given set of Series. When nil (default), all Series are displayed.
	// An index of the Series or the name of the Series can be provided.
	//
	// NOTE: This option only applies to DataFrames.
	//
	// Example:
	//
	//  opts :=  TableOptions{Series: []interface{}{1, "time"}}
	//
	Series []interface{}

	// R is used to limit the range of rows.
	R *Range

	// DontLock can be set to true if the DataFrame or Series should not be locked.
	DontLock bool
}

TableOptions can be used to limit the number of rows and which Series are used when generating the table.

type ToSeriesFloat64

type ToSeriesFloat64 interface {

	// ToSeriesFloat64 is used to convert a particular Series to a SeriesFloat64.
	// If the returned Series is not nil but an error is still provided,
	// it means that some rows were not able to be converted. You can inspect
	// the error to determine which rows were unconverted.
	//
	// NOTE: The returned ErrorCollection should contain RowError objects.
	ToSeriesFloat64(context.Context, bool, ...func(interface{}) (float64, error)) (*SeriesFloat64, error)
}

ToSeriesFloat64 is an interface used by the Dataframe to know if a particular Series can be converted to a SeriesFloat64 Series.

type ToSeriesInt64

type ToSeriesInt64 interface {

	// ToSeriesInt64 is used to convert a particular Series to a SeriesInt64.
	// If the returned Series is not nil but an error is still provided,
	// it means that some rows were not able to be converted. You can inspect
	// the error to determine which rows were unconverted.
	//
	// NOTE: The returned ErrorCollection should contain RowError objects.
	ToSeriesInt64(context.Context, bool, ...func(interface{}) (*int64, error)) (*SeriesInt64, error)
}

ToSeriesInt64 is an interface used by the Dataframe to know if a particular Series can be converted to a SeriesInt64 Series.

type ToSeriesMixed

type ToSeriesMixed interface {

	// ToSeriesMixed is used to convert a particular Series to a ToSeriesMixed.
	// If the returned Series is not nil but an error is still provided,
	// it means that some rows were not able to be converted. You can inspect
	// the error to determine which rows were unconverted.
	//
	// NOTE: The returned ErrorCollection should contain RowError objects.
	ToSeriesMixed(context.Context, bool, ...func(interface{}) (interface{}, error)) (*SeriesMixed, error)
}

ToSeriesMixed is an interface used by the Dataframe to know if a particular Series can be converted to a ToSeriesMixed Series.

type ToSeriesString

type ToSeriesString interface {

	// ToSeriesString is used to convert a particular Series to a SeriesString.
	// If the returned Series is not nil but an error is still provided,
	// it means that some rows were not able to be converted. You can inspect
	// the error to determine which rows were unconverted.
	//
	// NOTE: The returned ErrorCollection should contain RowError objects.
	ToSeriesString(context.Context, bool, ...func(interface{}) (*string, error)) (*SeriesString, error)
}

ToSeriesString is an interface used by the Dataframe to know if a particular Series can be converted to a SeriesString Series.

type ValueToStringFormatter

type ValueToStringFormatter func(val interface{}) string

ValueToStringFormatter is used to convert a value into a string. Val can be nil or the concrete type stored by the series.

type ValuesOptions

type ValuesOptions struct {

	// InitialRow represents the starting value for iterating.
	// Negative values are acceptable. A value of -2 means the second last row.
	InitialRow int

	// Step represents by how much each iteration should step by.
	// It can be negative to represent iterating in reverse direction.
	// InitialRow should be adjusted to -1 if Step is negative.
	// If Step is 0, the function will panic.
	Step int

	// Don't apply read lock. This is useful if you intend to Write lock
	// the entire dataframe.
	DontReadLock bool
}

ValuesOptions is used to modify the behavior of Values().

Directories

Path Synopsis
Package exports provides functionality to save the data contained in a DataFrame into another format.
Package exports provides functionality to save the data contained in a DataFrame into another format.
Package forecast provides an interface for custom forecasting algorithms.
Package forecast provides an interface for custom forecasting algorithms.
algs/hw
Package hw implements the Holt-Winters forecasting algorithm.
Package hw implements the Holt-Winters forecasting algorithm.
algs/ses
Package ses implements the simple exponential smooting forecasting algorithm.
Package ses implements the simple exponential smooting forecasting algorithm.
interpolation
Package interpolation implements various algorithms to fill in missing values in a Series or DataFrame.
Package interpolation implements various algorithms to fill in missing values in a Series or DataFrame.
Package imports provides functionality to read data contained in another format to populate a DataFrame.
Package imports provides functionality to read data contained in another format to populate a DataFrame.
math
funcs
Package funcs provides functionality to apply mathematical functions to DataFrames.
Package funcs provides functionality to apply mathematical functions to DataFrames.
matrix
Package matrix can be used to wrap a DataFrame such that it implements the Matrix interface found in various external packages such as gonum.
Package matrix can be used to wrap a DataFrame such that it implements the Matrix interface found in various external packages such as gonum.
Package pandas contains functionality that mirrors python's popular pandas library.
Package pandas contains functionality that mirrors python's popular pandas library.
Package plot implements basic plotting functionality that leverages Chrome/Chromium for cross-platform capabilities.
Package plot implements basic plotting functionality that leverages Chrome/Chromium for cross-platform capabilities.
faker
Package faker can be used to generate DataFrames filled with fake data.
Package faker can be used to generate DataFrames filled with fake data.
Package xseries contains specialized and/or "exotic" Series types that don't belong in the core package.
Package xseries contains specialized and/or "exotic" Series types that don't belong in the core package.

Jump to

Keyboard shortcuts

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