dataframe

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 17 Imported by: 1

Documentation

Overview

Package dataframe defines the DataFrame, a 2-dimensional data structure with an n-level index, n-level column headers, and columns of typed data. It is analogous to a spreadsheet.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(df, df2 *DataFrame) bool

Equal returns true if two dataframes contain equivalent values.

Types

type Columns

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

Columns contains column level data.

Example (Valid_printer)
df := MustNew([]interface{}{[]string{"foo", "bar", "baz"}})
fmt.Println(df.Columns)
Output:

{DataFrame Columns | NumCols: 1, NumLevels: 1}

func (Columns) AppendLevel

func (col Columns) AppendLevel(labels []string, name string) error

AppendLevel adds a new cols level to the end of the current cols and modifies the DataFrame in place.

func (Columns) At

func (col Columns) At(level int, column int) string

At returns the cols values at a specified col level and column position but returns nil if either integer is out of range.

func (Columns) DropLevel

func (col Columns) DropLevel(level int) error

DropLevel drops the specified cols level and modifies the DataFrame in place. If there is only one col level remaining, replaces with a new default col level.

func (Columns) InsertLevel

func (col Columns) InsertLevel(pos int, labels []string, name string) error

InsertLevel inserts a level into the cols and modifies the DataFrame in place.

func (Columns) RenameLevel

func (col Columns) RenameLevel(level int, name string) error

RenameLevel renames an cols level in place but does not change anything if level is out of range.

func (Columns) Reorder

func (col Columns) Reorder(labels []string)

Reorder reorders the columns in the order in which the labels are supplied and excludes any unsupplied labels. Reorder looks for these labels in level 0 and modifies the DataFrame in place.

func (Columns) SelectName

func (col Columns) SelectName(name string) int

SelectName returns the integer position of the cols level at the first occurrence of the supplied name, or -1 if not a valid cols level name.

func (Columns) SelectNames

func (col Columns) SelectNames(names []string) []int

SelectNames returns the integer positions of the cols levels with the supplied names.

func (Columns) String

func (col Columns) String() string

func (Columns) SubsetLevels

func (col Columns) SubsetLevels(levelPositions []int) error

SubsetLevels modifies the DataFrame in place with only the specified cols levels.

func (Columns) SwapLevels

func (col Columns) SwapLevels(i, j int) error

SwapLevels swaps two column levels and modifies the cols in place.

func (Columns) Values

func (col Columns) Values() [][]string

Values returns an []string of the values at each level of the cols.

type Config

type Config struct {
	Name            string
	DataType        options.DataType
	Index           interface{}
	IndexName       string
	MultiIndex      []interface{}
	MultiIndexNames []string
	Col             []string
	ColName         string
	MultiCol        [][]string
	MultiColNames   []string
	Manual          bool
}

Config customizes the DataFrame constructor.

type DataFrame

type DataFrame struct {
	Columns Columns

	Index   Index
	InPlace InPlace
	// contains filtered or unexported fields
}

A DataFrame is a 2D collection of one or more Series with a shared index and associated columns.

Example (Empty_df)
df := newEmptyDataFrame()
fmt.Println(df)
Output:

{Empty DataFrame}
Example (MultiCol_col)

Selects the first column with this label from the first level

df, err := New([]interface{}{[]int{1, 3, 5}, []string{"foo", "bar", "baz"}},
	Config{MultiCol: [][]string{{"qux", "qux"}, {"quux", "quuz"}}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df.Col("qux"))
Output:

0    1
1    3
2    5

datatype: int64
name: qux | quux

func MustNew

func MustNew(data []interface{}, config ...Config) *DataFrame

MustNew constructs a new DataFrame or logs an error and returns an empty DataFrame.

func New

func New(data []interface{}, config ...Config) (*DataFrame, error)

New creates a new DataFrame with default column names.

Example (Datetime)
df, err := New([]interface{}{[]time.Time{time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2019, 1, 2, 0, 0, 0, 0, time.UTC)}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

                     0
0    1/1/2019T00:00:00
1    1/2/2019T00:00:00

datatype: dateTime
Example (Empty_dataframe)
df := MustNew(nil)
fmt.Println(df)
Output:

{Empty DataFrame}
Example (Exceed_maxColumns_even)
options.SetDisplayMaxColumns(4)
s := MustNew([]interface{}{0, 1, 2, 3, 4})
fmt.Println(s)
options.RestoreDefaults()
Output:

     0  1  ...  3  4
0    0  1       3  4

datatype: int64
Example (Exceed_maxColumns_odd)
options.SetDisplayMaxColumns(3)
s := MustNew([]interface{}{0, 1, 2, 3, 4})
fmt.Println(s)
options.RestoreDefaults()
Output:

     0  1  ...  4
0    0  1       4

datatype: int64
Example (Exceed_maxRows_even)
options.SetDisplayMaxRows(2)
s := MustNew([]interface{}{[]float64{0, 1, 2, 3, 4}})
fmt.Println(s)
options.RestoreDefaults()
Output:

        0
0    0.00
...
4    4.00

datatype: float64
Example (Exceed_maxRows_odd)
options.SetDisplayMaxRows(3)
s := MustNew([]interface{}{[]float64{0, 1, 2, 3, 4}})
fmt.Println(s)
options.RestoreDefaults()
Output:

        0
0    0.00
1    1.00
...
4    4.00

datatype: float64
Example (Float64)
df, err := New(
	[]interface{}{[]float64{0, 1.5}, []float64{2.5, 3}},
	Config{
		Index: []string{"foo", "bar"},
		Col:   []string{"baz", "qux"},
	})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

        baz   qux
foo    0.00  2.50
bar    1.50  3.00

datatype: float64
Example (Float64_colsNamed_repeat_allowed)
options.SetDisplayRepeatedLabels(true)
df := MustNew([]interface{}{"qux", "bar", "fred"},
	Config{Name: "foobar", Col: []string{"waldo", "waldo", "foo"}})
fmt.Println(df)
options.RestoreDefaults()
Output:

     waldo  waldo   foo
0      qux    bar  fred

datatype: string
name: foobar
Example (Float64_colsNamed_repeat_resume)
df := MustNew([]interface{}{"qux", "bar", "fred"},
	Config{Name: "foobar", Col: []string{"waldo", "waldo", "foo"}})
fmt.Println(df)
Output:

     waldo        foo
0      qux  bar  fred

datatype: string
name: foobar
Example (Float64_indexNamed_multicolNamed)
df, err := New([]interface{}{"qux", "waldo"},
	Config{
		Name:  "foobar",
		Index: "foo", IndexName: "grault",
		MultiCol: [][]string{{"quux", "quux"}, {"bar", "baz"}}, MultiColNames: []string{"quuz", "garply"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

grault
            quuz quux
          garply  bar    baz
   foo            qux  waldo

datatype: string
name: foobar
Example (MaxWidth_index)
options.SetDisplayMaxWidth(10)
df := MustNew([]interface{}{[]string{"foo", "bar"}}, Config{Index: []string{"This is a very long index row. Very long indeed.", "qux"}, IndexName: "baz"})
fmt.Println(df)
options.RestoreDefaults()
Output:

       baz
                0
This is...    foo
       qux    bar

datatype: string
Example (MaxWidth_value)
s := MustNew([]interface{}{[]string{"This is a very long value row. Very long indeed.", "foo"}})
fmt.Println(s)
Output:

                                       0
0    This is a very long value row. V...
1                                    foo

datatype: string
Example (No_interpolation)
df := MustNew([]interface{}{[]interface{}{"foo", "bar"}}, Config{Manual: true})
fmt.Println(df)
Output:

       0
0    foo
1    bar

datatype: interface
Example (String_colsNamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", Col: []string{"baz", "qux"}, ColName: "corge"})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

     corge baz  qux
0          foo  bar

datatype: string
name: foobar
Example (String_colsUnnamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", Col: []string{"baz", "qux"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

     baz  qux
0    foo  bar

datatype: string
name: foobar
Example (String_indexNamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", Index: "baz", IndexName: "qux"})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

qux
         0    1
baz    foo  bar

datatype: string
name: foobar
Example (String_indexNamed_colsNamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar",
		Index: "baz", IndexName: "corge",
		Col: []string{"quux", "qux"}, ColName: "quuz"})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

corge
         quuz quux  qux
  baz          foo  bar

datatype: string
name: foobar
Example (String_indexNamed_colsUnnamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar",
		Index: "baz", IndexName: "corge",
		Col: []string{"quux", "qux"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

corge
         quux  qux
  baz     foo  bar

datatype: string
name: foobar
Example (String_indexRepeated)
df, err := New([]interface{}{[]string{"foo", "bar"}},
	Config{Name: "foobar", Index: []string{"baz", "baz"}, IndexName: "qux"})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

qux
         0
baz    foo
       bar

datatype: string
name: foobar
Example (String_indexRepeated_allowed)
options.SetDisplayRepeatedLabels(true)
df, err := New([]interface{}{[]string{"foo", "bar"}},
	Config{Name: "foobar", Index: []string{"baz", "baz"}, IndexName: "qux"})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
options.RestoreDefaults()
Output:

qux
         0
baz    foo
baz    bar

datatype: string
name: foobar
Example (String_indexUnnamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", Index: "baz"})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

         0    1
baz    foo  bar

datatype: string
name: foobar
Example (String_multiIndexNamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", MultiIndex: []interface{}{"baz", "corge"}, MultiIndexNames: []string{"qux", "quux"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

qux  quux
               0    1
baz corge    foo  bar

datatype: string
name: foobar
Example (String_multiIndexUnnamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", MultiIndex: []interface{}{"baz", "corge"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

               0    1
baz corge    foo  bar

datatype: string
name: foobar
Example (String_multicolNamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", MultiCol: [][]string{{"quux", "quax"}, {"baz", "qux"}}, MultiColNames: []string{"corge", "grault"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

      corge quux  quax
     grault  baz   qux
0            foo   bar

datatype: string
name: foobar
Example (String_multicolNamed_repeat)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", MultiCol: [][]string{{"quux", "quux"}, {"baz", "qux"}}, MultiColNames: []string{"corge", "grault"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

      corge quux
     grault  baz  qux
0            foo  bar

datatype: string
name: foobar
Example (String_multicolUnnamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar", MultiCol: [][]string{{"quux", "quux"}, {"baz", "qux"}}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

     quux
      baz  qux
0     foo  bar

datatype: string
name: foobar
Example (String_multiindexNamed_colsNamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar",
		MultiIndex: []interface{}{"baz", "garply"}, MultiIndexNames: []string{"corge", "grault"},
		Col: []string{"quux", "qux"}, ColName: "quuz"})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

corge grault
                quuz quux  qux
  baz garply          foo  bar

datatype: string
name: foobar
Example (String_multiindexNamed_multicolNamed)
df, err := New([]interface{}{"foo", "bar"},
	Config{Name: "foobar",
		MultiIndex: []interface{}{"baz", "garply"}, MultiIndexNames: []string{"grault", "corge"},
		MultiCol: [][]string{{"fred", "fred"}, {"quux", "qux"}}, MultiColNames: []string{"waldo", "quuz"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df)
Output:

grault  corge
                 waldo fred
                  quuz quux  qux
   baz garply           foo  bar

datatype: string
name: foobar

func (*DataFrame) AppendCol

func (df *DataFrame) AppendCol(s *series.Series, colLabels ...string) (*DataFrame, error)

AppendCol adds a column at the end and returns a new DataFrame.

func (*DataFrame) AppendRow

func (df *DataFrame) AppendRow(val []interface{}, idxLabels ...interface{}) (*DataFrame, error)

AppendRow adds a row at the end and returns a new DataFrame.

func (*DataFrame) Col

func (df *DataFrame) Col(label string) *series.Series

Col returns the first Series with the specified column label at column level 0.

Example
df, err := New([]interface{}{[]float64{1, 3, 5}, []string{"foo", "bar", "baz"}}, Config{Col: []string{"qux", "corge"}})
if err != nil {
	log.Fatal(err)
}
fmt.Println(df.Col("corge"))
Output:

0    foo
1    bar
2    baz

datatype: string
name: corge

func (*DataFrame) ColAt

func (df *DataFrame) ColAt(col int) *series.Series

ColAt returns the Series at the specified column.

func (*DataFrame) ColLevels

func (df *DataFrame) ColLevels() int

ColLevels returns the number of column levels in the DataFrame.

func (*DataFrame) Convert

func (df *DataFrame) Convert(dataType string) (*DataFrame, error)

Convert converts every series in a DataFrame to datatype and returns a new DataFrame.

func (*DataFrame) Copy

func (df *DataFrame) Copy() *DataFrame

Copy creates a new deep copy of a Series.

func (*DataFrame) DataTypes

func (df *DataFrame) DataTypes() *series.Series

DataTypes returns the DataTypes of the Series in the DataFrame.

func (*DataFrame) DropCol

func (df *DataFrame) DropCol(col int) (*DataFrame, error)

DropCol drops the column at the specified integer position and returns a new DataFrame.

func (*DataFrame) DropCols

func (df *DataFrame) DropCols(columnPositions []int) (*DataFrame, error)

DropCols drops the column at the specified integer position and returns a new DataFrame.

func (*DataFrame) DropDuplicates

func (df *DataFrame) DropDuplicates() *DataFrame

DropDuplicates drops any rows containing duplicate index + DataFrame values and returns a new DataFrame.

func (*DataFrame) DropNull

func (df *DataFrame) DropNull(cols ...int) *DataFrame

DropNull drops all null values and returns a new DataFrame. If an invalid column is provided, returns a copy of the original DataFrame.

func (*DataFrame) DropRow

func (df *DataFrame) DropRow(row int) (*DataFrame, error)

DropRow drops the row at the specified integer position and returns a new DataFrame.

func (*DataFrame) DropRows

func (df *DataFrame) DropRows(positions []int) (*DataFrame, error)

DropRows drops the rows at the specified integer position and returns a new DataFrame.

func (*DataFrame) Export

func (df *DataFrame) Export() [][]interface{}

Export converts index, columns, and values to [][]interface{}{row1{col1, col2, ...}, ...}.

func (*DataFrame) ExportToCSV

func (df *DataFrame) ExportToCSV(filepath string)

ExportToCSV exports the DataFrame to a CSV file.

func (*DataFrame) GroupBy

func (df *DataFrame) GroupBy(cols ...int) Grouping

GroupBy groups a DataFrame by one or more columns. If no column is supplied or an invalid column is supplied, an empty grouping is returned.

func (*DataFrame) GroupByIndex

func (df *DataFrame) GroupByIndex(levelPositions ...int) Grouping

GroupByIndex groups a DataFrame by one or more of its index levels. If no level is provided, all index levels are used.

func (*DataFrame) Head

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

Head returns the first n rows of the DataFrame.

func (*DataFrame) IndexLevels

func (df *DataFrame) IndexLevels() int

IndexLevels returns the number of index levels in the DataFrame.

func (*DataFrame) InsertCol

func (df *DataFrame) InsertCol(row int, s *series.Series, colLabels ...string) (*DataFrame, error)

InsertCol inserts a new column into the DataFrame immediately before the specified integer position and returns a new DataFrame.

func (*DataFrame) InsertRow

func (df *DataFrame) InsertRow(row int, val []interface{}, idxLabels ...interface{}) (*DataFrame, error)

InsertRow inserts a new row into the DataFrame immediately before the specified integer position and returns a new DataFrame.

func (*DataFrame) Len

func (df *DataFrame) Len() int

Len returns the number of values in each Series of the DataFrame.

func (*DataFrame) Max

func (df *DataFrame) Max() *series.Series

Max all numerical columns.

func (*DataFrame) Mean

func (df *DataFrame) Mean() *series.Series

Mean of all numerical or boolean columns.

func (*DataFrame) Median

func (df *DataFrame) Median() *series.Series

Median of all numerical or boolean columns.

func (*DataFrame) Min

func (df *DataFrame) Min() *series.Series

Min all numerical columns.

func (*DataFrame) Name

func (df *DataFrame) Name() string

Name returns the DataFrame's name.

func (*DataFrame) NumCols

func (df *DataFrame) NumCols() int

NumCols returns the number of columns in the DataFrame.

func (*DataFrame) Pivot

func (df *DataFrame) Pivot(index int, values int, columns int, aggFunc string) (*DataFrame, error)

Pivot transforms data into the desired form and calls aggFunc on the reshaped data.

func (*DataFrame) Rename

func (df *DataFrame) Rename(name string)

Rename the DataFrame.

func (*DataFrame) RenameCols

func (df *DataFrame) RenameCols(columns map[string]string)

RenameCols renames the columns at the specified labels.

func (*DataFrame) ResetIndex

func (df *DataFrame) ResetIndex(level int) (*DataFrame, error)

ResetIndex sets an index level as a column, drops the index level, and returns a new DataFrame. If level is the only level, a default int index is inserted.

func (*DataFrame) Row

func (df *DataFrame) Row(position int) Row

Row returns information about the values and index labels in this row but panics if an out-of-range position is provided.

func (*DataFrame) SelectCol

func (df *DataFrame) SelectCol(label string) int

SelectCol returns the integer location of the first row in index level 0 with the supplied label, or -1 if the label does not exist.

func (*DataFrame) SelectCols

func (df *DataFrame) SelectCols(labels []string, level int) []int

SelectCols returns the integer locations of all columns with the supplied labels within the supplied level. If an error is encountered, returns a new slice of 0 length.

func (*DataFrame) SelectLabel

func (df *DataFrame) SelectLabel(label string) int

SelectLabel returns the integer location of the first row in index level 0 with the supplied label, or -1 if the label does not exist.

func (*DataFrame) SelectLabels

func (df *DataFrame) SelectLabels(labels []string, level int) []int

SelectLabels returns the integer locations of all rows with the supplied labels within the supplied level. If an error is encountered, returns a new slice of 0 length.

func (*DataFrame) Set

func (df *DataFrame) Set(colLabel string, s *series.Series) *DataFrame

Set selects the first column in column level 0 with the label and sets its values to s, then returns a new DataFrame. If an error occurs, the error is logged and nothing happens.

func (*DataFrame) SetCol

func (df *DataFrame) SetCol(col int, s *series.Series) (*DataFrame, error)

SetCol sets all the values in the specified columns to val and returns a new DataFrame.

func (*DataFrame) SetCols

func (df *DataFrame) SetCols(columnPositions []int, s *series.Series) (*DataFrame, error)

SetCols sets all the values in the specified columns to val and returns a new DataFrame.

func (*DataFrame) SetIndex

func (df *DataFrame) SetIndex(col int) (*DataFrame, error)

SetIndex sets a column as an index level, drops the column, and returns a new DataFrame. If col is the only column, nothing happens.

func (*DataFrame) SetRow

func (df *DataFrame) SetRow(row int, val interface{}) (*DataFrame, error)

SetRow sets the value in the specified rows to val and returns a new DataFrame.

func (*DataFrame) SetRows

func (df *DataFrame) SetRows(rowPositions []int, val interface{}) (*DataFrame, error)

SetRows sets all the values in the specified rows to val and returns a new DataFrame.

func (*DataFrame) Std

func (df *DataFrame) Std() *series.Series

Std returns the standard deviation of all numerical columns.

func (*DataFrame) String

func (df *DataFrame) String() string

func (*DataFrame) SubsetColumns

func (df *DataFrame) SubsetColumns(columnPositions []int) (*DataFrame, error)

SubsetColumns subsets a DataFrame to include only the columns at supplied integer positions and returns a new DataFrame.

func (*DataFrame) SubsetRows

func (df *DataFrame) SubsetRows(rowPositions []int) (*DataFrame, error)

SubsetRows subsets a DataFrame to include only the rows at supplied integer positions and returns a new DataFrame.

func (*DataFrame) Sum

func (df *DataFrame) Sum() *series.Series

Sum all numerical or boolean columns.

func (*DataFrame) SwapColumns

func (df *DataFrame) SwapColumns(i, j int) (*DataFrame, error)

SwapColumns swaps the selected rows and returns a new DataFrame.

func (*DataFrame) SwapRows

func (df *DataFrame) SwapRows(i, j int) (*DataFrame, error)

SwapRows swaps the selected rows and returns a new DataFrame.

func (*DataFrame) Tail

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

Tail returns the last n rows of the DataFrame.

func (*DataFrame) ToBool

func (df *DataFrame) ToBool() *DataFrame

ToBool converts DataFrame values to bool and returns a new DataFrame.

func (*DataFrame) ToDateTime

func (df *DataFrame) ToDateTime() *DataFrame

ToDateTime converts DataFrame values to time.Time and returns a new DataFrame.

func (*DataFrame) ToFloat64

func (df *DataFrame) ToFloat64() *DataFrame

ToFloat64 converts DataFrame values to float64 and returns a new DataFrame.

func (*DataFrame) ToInt64

func (df *DataFrame) ToInt64() *DataFrame

ToInt64 converts DataFrame values to int64 and returns a new DataFrame.

func (*DataFrame) ToInterface

func (df *DataFrame) ToInterface() *DataFrame

ToInterface converts DataFrame values to interface and returns a new DataFrame.

func (*DataFrame) ToString

func (df *DataFrame) ToString() *DataFrame

ToString converts DataFrame values to string and returns a new DataFrame.

func (*DataFrame) Transpose

func (df *DataFrame) Transpose() *DataFrame

Transpose transforms all rows to columns.

type Grouping

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

A Grouping returns a collection of index labels with mutually exclusive integer positions.

Example (Method_list)
s := MustNew(
	[]interface{}{[]string{"foo", "bar", "baz"}},
	Config{MultiIndex: []interface{}{[]int{0, 0, 1}, []int{100, 100, 101}}})
g := s.GroupByIndex()
fmt.Println(g)
Output:

{DataFrame Grouping | NumGroups: 2, Groups: [0 | 100, 1 | 101]}

func (Grouping) First

func (g Grouping) First() *DataFrame

First returns the first occurrence of each grouping in the DataFrame.

func (Grouping) Group

func (g Grouping) Group(label string) *DataFrame

Group returns the DataFrame with the given group label, or an error if that label does not exist.

func (Grouping) Groups

func (g Grouping) Groups() []string

Groups returns all valid group labels in the Grouping, in their original group position.

func (Grouping) Last

func (g Grouping) Last() *DataFrame

Last returns the last occurrence of each grouping in the DataFrame.

func (Grouping) Len

func (g Grouping) Len() int

Len returns the number of groups in the Grouping.

func (Grouping) Max

func (g Grouping) Max() *DataFrame

Max for each group in the Grouping.

func (Grouping) Mean

func (g Grouping) Mean() *DataFrame

Mean for each group in the Grouping.

func (Grouping) Median

func (g Grouping) Median() *DataFrame

Median for each group in the Grouping.

func (Grouping) Min

func (g Grouping) Min() *DataFrame

Min for each group in the Grouping.

func (Grouping) SortedGroups

func (g Grouping) SortedGroups() []string

SortedGroups returns all valid group labels in the Grouping, sorted in alphabetical order.

func (Grouping) Std

func (g Grouping) Std() *DataFrame

Std for each group in the Grouping.

func (Grouping) String

func (g Grouping) String() string

func (Grouping) Sum

func (g Grouping) Sum() *DataFrame

Sum for each group in the Grouping.

type InPlace

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

InPlace contains methods for modifying a DataFrame in place.

Example (Method_list)
df := MustNew([]interface{}{"foo"})
fmt.Println(df.InPlace)
Output:

{InPlace DataFrame Handler}
Methods:
AppendCol
AppendRow
Convert
DropCol
DropCols
DropDuplicates
DropNull
DropRow
DropRows
InsertCol
InsertRow
Len
ResetIndex
Set
SetCol
SetCols
SetIndex
SetRow
SetRows
String
SubsetColumns
SubsetRows
SwapColumns
SwapRows
ToBool
ToDateTime
ToFloat64
ToInt64
ToInterface
ToString

func (InPlace) AppendCol

func (ip InPlace) AppendCol(s *series.Series, colLabels ...string) error

AppendCol adds a row at a specified integer position and modifies the DataFrame in place. TODO take colLabels from series

func (InPlace) AppendRow

func (ip InPlace) AppendRow(val []interface{}, idxLabels ...interface{}) error

AppendRow adds a row at a specified integer position and modifies the DataFrame in place.

func (InPlace) Convert

func (ip InPlace) Convert(dataType string) error

Convert converts every series in a DataFrame to datatype and modifies the DataFrame in place.

func (InPlace) DropCol

func (ip InPlace) DropCol(col int) error

DropCol drops a column at a specified integer position and modifies the DataFrame in place.

func (InPlace) DropCols

func (ip InPlace) DropCols(columnPositions []int) error

DropCols drops the columns at the specified integer positions and modifies the DataFrame in place.

func (InPlace) DropDuplicates

func (ip InPlace) DropDuplicates()

DropDuplicates drops any rows containing duplicate index + DataFrame values and modifies the DataFrame in place.

func (InPlace) DropNull

func (ip InPlace) DropNull(cols ...int)

DropNull drops all null values and modifies the DataFrame in place. If an invalid column is provided, returns original DataFrame.

func (InPlace) DropRow

func (ip InPlace) DropRow(row int) error

DropRow drops the row at the specified integer position and modifies the DataFrame in place.

func (InPlace) DropRows

func (ip InPlace) DropRows(rowPositions []int) error

DropRows drops the rows at the specified integer position and modifies the DataFrame in place. If an error would be encountered in any row position, the entire operation is cancelled before it starts.

func (InPlace) InsertCol

func (ip InPlace) InsertCol(col int, s *series.Series, colLabels ...string) error

InsertCol inserts a column with an indefinite number of column labels immediately before the specified column position and modifies the DataFrame in place. TODO: derive colLabels from name

func (InPlace) InsertRow

func (ip InPlace) InsertRow(row int, val []interface{}, idxLabels ...interface{}) error

InsertRow inserts a new row into the DataFrame immediately before the specified integer position and modifies the DataFrame in place. If the original DataFrame is empty, replaces it with a new DataFrame.

func (InPlace) Len

func (ip InPlace) Len() int

Len returns the length of the underlying DataFrame (required by Sort interface)

func (InPlace) ResetIndex

func (ip InPlace) ResetIndex(level int) error

ResetIndex sets an index level as a column, drops the index level, and modifies the DataFrame in place. If level is the only level, a default int index is inserted.

func (InPlace) Set

func (ip InPlace) Set(colLabel string, s *series.Series)

Set selects the first column in column level 0 with the label and sets its values to s. If an error occurs, the error is logged and nothing happens.

func (InPlace) SetCol

func (ip InPlace) SetCol(col int, s *series.Series) error

SetCol sets the values in the specified column to val and modifies the DataFrame in place.

func (InPlace) SetCols

func (ip InPlace) SetCols(columnPositions []int, s *series.Series) error

SetCols sets the values in the specified columns to val and modifies the DataFrame in place.

func (InPlace) SetIndex

func (ip InPlace) SetIndex(col int) error

SetIndex sets a column as an index level, drops the column, and modifies the DataFrame in place. If col is the only column, nothing happens.

func (InPlace) SetRow

func (ip InPlace) SetRow(row int, val interface{}) error

SetRow sets the values in the specified row to val and modifies the DataFrame in place. First converts val to be the same type as the index level.

func (InPlace) SetRows

func (ip InPlace) SetRows(rowPositions []int, val interface{}) error

SetRows sets all the values in the specified rows to val and modifies the DataFrame in place. First converts val to be the same type as the index level. If an error would be encountered in any row position, the entire operation is cancelled before it starts.

func (InPlace) String

func (ip InPlace) String() string

func (InPlace) SubsetColumns

func (ip InPlace) SubsetColumns(columnPositions []int) error

SubsetColumns subsets a DataFrame to include only the columns at supplied integer positions and modifies the DataFrame in place.

func (InPlace) SubsetRows

func (ip InPlace) SubsetRows(rowPositions []int) error

SubsetRows subsets a DataFrame to include only the rows at supplied integer positions and modifies the DataFrame in place.

func (InPlace) SwapColumns

func (ip InPlace) SwapColumns(i, j int)

SwapColumns swaps the selected columns in place.

func (InPlace) SwapRows

func (ip InPlace) SwapRows(i, j int)

SwapRows swaps the selected rows in place.

func (InPlace) ToBool

func (ip InPlace) ToBool()

ToBool converts DataFrame values to bool in place.

func (InPlace) ToDateTime

func (ip InPlace) ToDateTime()

ToDateTime converts DataFrame values to datetime in place.

func (InPlace) ToFloat64

func (ip InPlace) ToFloat64()

ToFloat64 converts DataFrame values to float64 in place.

func (InPlace) ToInt64

func (ip InPlace) ToInt64()

ToInt64 converts DataFrame values to int64 in place.

func (InPlace) ToInterface

func (ip InPlace) ToInterface()

ToInterface converts DataFrame values to interface in place.

func (InPlace) ToString

func (ip InPlace) ToString()

ToString converts DataFrame values to string in place.

type Index

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

Index contains index level data.

Example (Valid_printer)
df := MustNew([]interface{}{[]string{"foo", "bar", "baz"}})
fmt.Println(df.Index)
Output:

{DataFrame Index | Len: 3, NumLevels: 1}

func (Index) AppendLevel

func (idx Index) AppendLevel(values interface{}, name string) error

AppendLevel adds a new index level to the end of the current index and modifies the DataFrame in place.

func (Index) At

func (idx Index) At(row int, level int) interface{}

At returns the index values at a specified row position and index level but returns nil if either integer is out of range.

func (Index) Convert

func (idx Index) Convert(dataType string, level int) error

Convert converts an index level to datatype in place.

func (Index) DropLevel

func (idx Index) DropLevel(level int) error

DropLevel drops the specified index level and modifies the DataFrame in place.

func (Index) DropNull

func (idx Index) DropNull(level int) error

DropNull drops null index values at the index level specified and modifies the DataFrame in place.

func (Index) Filter

func (idx Index) Filter(level int, cmp func(interface{}) bool) []int

Filter an index level using a callback function test. The Filter function iterates over all index values in interface{} form and applies the callback test to each. The return value is a slice of integer positions of all the rows passing the test. The caller is responsible for handling the type assertion on the interface, though this step is not necessary if the datatype is known with certainty. For example, here are two ways to write a filter that returns all rows with the suffix "boo":

#1 (safer) error check type assertion

 s.Index.Filter(0, func(val interface{}) bool {
		v, ok := val.(string)
		if !ok {
			return false
		}
		if strings.HasSuffix(v, "boo") {
			return true
		}
		return false
	})

Input: bamboo 0 leaves 1 taboo 2

Output: []int{0,2}

#2 (riskier) no error check

 s.Filter(func(val interface{}) bool {
		if strings.HasSuffix(val.(string), "boo") {
			return true
		}
		return false
	})

func (Index) Flip

func (idx Index) Flip(col int, level int) (*DataFrame, error)

Flip replaces the DataFrame values at the supplied column with the labels at the supplied index level, and vice versa.

func (Index) InsertLevel

func (idx Index) InsertLevel(pos int, values interface{}, name string) error

InsertLevel inserts a level into the index and modifies the DataFrame in place.

func (Index) Len

func (idx Index) Len() int

Len returns the number of items in each level of the index.

func (Index) Less

func (idx Index) Less(i, j int) bool

Less compares two elements and returns true if the first is less than the second. Required by Sort interface.

func (Index) Reindex

func (idx Index) Reindex(level int) error

Reindex converts an index level to a default range []int{0, 1, 2,...n}

func (Index) RenameLevel

func (idx Index) RenameLevel(level int, name string) error

RenameLevel renames an index level in place but does not change anything if level is out of range.

func (Index) SelectName

func (idx Index) SelectName(name string) int

SelectName returns the integer position of the index level at the first occurrence of the supplied name, or -1 if not a valid index level name.

func (Index) SelectNames

func (idx Index) SelectNames(names []string) []int

SelectNames returns the integer positions of the index levels with the supplied names.

func (Index) Set

func (idx Index) Set(row int, level int, val interface{}) error

Set sets the label at the specified index row and level to val and modifies the DataFrame in place. First converts val to be the same type as the index level.

func (Index) Sort

func (idx Index) Sort(asc bool)

Sort sorts the index by index level 0 and returns a new index.

func (Index) String

func (idx Index) String() string

func (Index) SubsetLevels

func (idx Index) SubsetLevels(levelPositions []int) error

SubsetLevels modifies the DataFrame in place with only the specified index levels.

func (Index) Swap

func (idx Index) Swap(i, j int)

Swap swaps two labels at index level 0 and modifies the index in place. Required by Sort interface.

func (Index) SwapLevels

func (idx Index) SwapLevels(i, j int) error

SwapLevels swaps two levels in the index and modifies the DataFrame in place.

func (Index) Values

func (idx Index) Values() [][]interface{}

Values returns an []interface{} of the values at each level of the index

type Row

type Row struct {
	Values     []interface{}
	Nulls      []bool
	ValueTypes []options.DataType
	Labels     []interface{}
	LabelTypes []options.DataType
}

A Row is a single row in a DataFrame.

Example (Valid_printer)
df := MustNew([]interface{}{"foo", 5, true, ""})
fmt.Println(df.Row(0))
Output:

	   Values: [foo 5 true NaN]
    IsNull: [false false false true]
ValueTypes: [string int64 bool string]
    Labels: [0]
LabelTypes: [int64]

func (Row) String

func (r Row) String() string

Jump to

Keyboard shortcuts

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