dataframe

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDateIndexNotAligned = errors.New("date index does not align")
)

Functions

This section is empty.

Types

type DataFrame

type DataFrame struct {
	Dates    []time.Time
	ColNames []string
	Vals     [][]float64
}

DataFrame stores a table of values organized by date the vals array is row major - e.g., VFINX PRIDX 1 4 2 5 3 6

Vals[0][0] = 1 Vals[0][1] = 2

func Mean

func Mean(dfs ...*DataFrame) *DataFrame

Mean calculates the mean of all like columns in the dataframes and returns a new dataframe panics if rows are not equal.

func (*DataFrame) AddScalar

func (df *DataFrame) AddScalar(scalar float64) *DataFrame

AddScalar adds the scalar value to all columns in dataframe df and returns a new dataframe panics if rows are not equal.

func (*DataFrame) AddVec

func (df *DataFrame) AddVec(vec []float64) *DataFrame

AddVec adds the vector to all columns in dataframe and returns a new dataframe panics if rows are not equal.

func (*DataFrame) Append

func (df *DataFrame) Append(other *DataFrame) *DataFrame

Append takes the date and values from other and appends them to df. If cols do not align, cols in df that are not in other are filled with NaN. If the start date of other is not greater than df then do nothing

func (*DataFrame) Breakout

func (df *DataFrame) Breakout() Map

Breakout takes a dataframe with multiple columns and returns a map of dataframes, one per column

func (*DataFrame) ColCount

func (df *DataFrame) ColCount() int

ColCount returns the number of columns in the dataframe

func (*DataFrame) Copy

func (df *DataFrame) Copy() *DataFrame

Copy creates a copy of the dataframe

func (*DataFrame) Count

func (df *DataFrame) Count(lambda func(x float64) bool) *DataFrame

Count creates a new dataframe with the number of columns where the expression lambda func(float64) bool evaluates to true is placed in the `count` column

func (*DataFrame) Div

func (df *DataFrame) Div(other *DataFrame) *DataFrame

Div divides all columns in `df` by the corresponding column in `other` and returns a new dataframe. Panics if rows are not equal.

func (*DataFrame) Drop

func (df *DataFrame) Drop(val float64) *DataFrame

Drop removes rows that contain the value `val` from the dataframe

func (*DataFrame) End

func (df *DataFrame) End() time.Time

End returns the last time in the DataFrame

func (*DataFrame) ForEach

func (df *DataFrame) ForEach(lambda func(int, time.Time, map[string]float64) map[string]float64)

ForEachMap takes a lambda function of prototype func(rowIdx int, rowDate time.Time, vals map[string]float64) map[string]float64 and updates the row with the returned value; if nil is returned then don't update the row, otherwise update row with returned values

func (*DataFrame) Frequency

func (df *DataFrame) Frequency(frequency Frequency) *DataFrame

Frequency returns a data frame filtered to the requested frequency; note this is not an in-place function but creates a copy of the data

func (*DataFrame) IdxMax

func (df *DataFrame) IdxMax() *DataFrame

IdxMax finds the column with the largest value for each row and stores it in a new dataframe with the column name 'idxmax'

func (*DataFrame) Insert

func (df *DataFrame) Insert(name string, col []float64) *DataFrame

Insert a new column to the end of the dataframe

func (*DataFrame) InsertMap

func (df *DataFrame) InsertMap(date time.Time, vals map[string]float64) *DataFrame

InsertMap adds a new row to the dataframe. Date must be after the last date in the dataframe otherwise panic. all columns must already exist in the dataframe, any additional columns in vals is ignored

func (*DataFrame) InsertRow

func (df *DataFrame) InsertRow(date time.Time, vals ...float64) *DataFrame

InsertRow adds a new row to the dataframe. Date must be after the last date in the dataframe and vals must equal the number of columns. If either of these conditions are not met then panic

func (*DataFrame) Lag

func (df *DataFrame) Lag(n int) *DataFrame

Lag shifts the dataframe by the specified number of rows, replacing shifted values by math.NaN() and returns a new dataframe

func (*DataFrame) Last

func (df *DataFrame) Last() *DataFrame

Last returns a new dataframe with only the last item of the current dataframe

func (*DataFrame) Len

func (df *DataFrame) Len() int

Len returns the number of rows in the dataframe

func (*DataFrame) Max

func (df *DataFrame) Max() *DataFrame

Max selects the max value for each row and returns a new dataframe

func (*DataFrame) Min

func (df *DataFrame) Min() *DataFrame

Min selects the min value for each row and returns a new dataframe

func (*DataFrame) Mul

func (df *DataFrame) Mul(other *DataFrame) *DataFrame

Mul multiplies all columns in dataframe df by the corresponding column in dataframe other and returns a new dataframe panics if rows are not equal.

func (*DataFrame) MulScalar

func (df *DataFrame) MulScalar(scalar float64) *DataFrame

MulScalar multiplies all columns in dataframe df by the scalar and returns a new dataframe panics if rows are not equal.

func (*DataFrame) RollingSumScaled

func (df *DataFrame) RollingSumScaled(ii int, scalar float64) *DataFrame

RollingSumScaled computes ∑ df[ii] * scalar and returns a new dataframe panics if rows are not equal.

func (*DataFrame) SMA

func (df *DataFrame) SMA(lookback int) *DataFrame

SMA computes the simple moving average of all the columns in df for the specified lookback period. The length of the resulting dataframe equals that of the input with NaNs during the warm-up period. Invalid lookback periods result in a dataframe of all NaN. NOTE: lookback is in terms of date periods. if the dataframe is sampled monthly then SMA is monthly,

func (*DataFrame) Split

func (df *DataFrame) Split(columns ...string) (*DataFrame, *DataFrame)

Split the dataframe into 2, with columns being in the first dataframe and all remaining columns in the second

func (*DataFrame) Start

func (df *DataFrame) Start() time.Time

Start returns the first date of the dataframe

func (*DataFrame) Table

func (df *DataFrame) Table() string

Table prints an ASCII formatted table to stdout

func (*DataFrame) Trim

func (df *DataFrame) Trim(begin, end time.Time) *DataFrame

Trim the dataframe to the specified date range (inclusive)

type Frequency

type Frequency string

Defines a time period - typically used to filter a dataframe

const (
	Daily      Frequency = "Daily"
	WeekBegin  Frequency = "WeekBegin"
	WeekEnd    Frequency = "WeekEnd"
	Weekly     Frequency = "WeekEnd"
	MonthBegin Frequency = "MonthBegin"
	MonthEnd   Frequency = "MonthEnd"
	Monthly    Frequency = "MonthEnd"
	YearBegin  Frequency = "YearBegin"
	YearEnd    Frequency = "YearEnd"
	Annually   Frequency = "YearEnd"
)

type Map

type Map map[string]*DataFrame

func (Map) Align

func (dfMap Map) Align() Map

Align finds the maximum start and minimum end across all dataframes and trims them to match

func (Map) DataFrame

func (dfMap Map) DataFrame() *DataFrame

DataFrame converts each item in the map to a column in the dataframe. If dataframes do not align they are trimmed to the max start and min end

func (Map) Drop

func (dfMap Map) Drop(val float64) Map

Drop calls dataframe.Drop on each dataframe in the map

func (Map) Frequency

func (dfMap Map) Frequency(frequency Frequency) Map

Jump to

Keyboard shortcuts

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