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 ¶
- func Equal(df, df2 *DataFrame) bool
- type Columns
- func (col Columns) AppendLevel(labels []string, name string) error
- func (col Columns) At(level int, column int) string
- func (col Columns) DropLevel(level int) error
- func (col Columns) InsertLevel(pos int, labels []string, name string) error
- func (col Columns) RenameLevel(level int, name string) error
- func (col Columns) Reorder(labels []string)
- func (col Columns) SelectName(name string) int
- func (col Columns) SelectNames(names []string) []int
- func (col Columns) String() string
- func (col Columns) SubsetLevels(levelPositions []int) error
- func (col Columns) SwapLevels(i, j int) error
- func (col Columns) Values() [][]string
- type Config
- type DataFrame
- func (df *DataFrame) AppendCol(s *series.Series, colLabels ...string) (*DataFrame, error)
- func (df *DataFrame) AppendRow(val []interface{}, idxLabels ...interface{}) (*DataFrame, error)
- func (df *DataFrame) Col(label string) *series.Series
- func (df *DataFrame) ColAt(col int) *series.Series
- func (df *DataFrame) ColLevels() int
- func (df *DataFrame) Convert(dataType string) (*DataFrame, error)
- func (df *DataFrame) Copy() *DataFrame
- func (df *DataFrame) DataTypes() *series.Series
- func (df *DataFrame) DropCol(col int) (*DataFrame, error)
- func (df *DataFrame) DropCols(columnPositions []int) (*DataFrame, error)
- func (df *DataFrame) DropDuplicates() *DataFrame
- func (df *DataFrame) DropNull(cols ...int) *DataFrame
- func (df *DataFrame) DropRow(row int) (*DataFrame, error)
- func (df *DataFrame) DropRows(positions []int) (*DataFrame, error)
- func (df *DataFrame) Export() [][]interface{}
- func (df *DataFrame) ExportToCSV(filepath string)
- func (df *DataFrame) GroupBy(cols ...int) Grouping
- func (df *DataFrame) GroupByIndex(levelPositions ...int) Grouping
- func (df *DataFrame) Head(n int) *DataFrame
- func (df *DataFrame) IndexLevels() int
- func (df *DataFrame) InsertCol(row int, s *series.Series, colLabels ...string) (*DataFrame, error)
- func (df *DataFrame) InsertRow(row int, val []interface{}, idxLabels ...interface{}) (*DataFrame, error)
- func (df *DataFrame) Len() int
- func (df *DataFrame) Max() *series.Series
- func (df *DataFrame) Mean() *series.Series
- func (df *DataFrame) Median() *series.Series
- func (df *DataFrame) Min() *series.Series
- func (df *DataFrame) Name() string
- func (df *DataFrame) NumCols() int
- func (df *DataFrame) Pivot(index int, values int, columns int, aggFunc string) (*DataFrame, error)
- func (df *DataFrame) Rename(name string)
- func (df *DataFrame) RenameCols(columns map[string]string)
- func (df *DataFrame) ResetIndex(level int) (*DataFrame, error)
- func (df *DataFrame) Row(position int) Row
- func (df *DataFrame) SelectCol(label string) int
- func (df *DataFrame) SelectCols(labels []string, level int) []int
- func (df *DataFrame) SelectLabel(label string) int
- func (df *DataFrame) SelectLabels(labels []string, level int) []int
- func (df *DataFrame) Set(colLabel string, s *series.Series) *DataFrame
- func (df *DataFrame) SetCol(col int, s *series.Series) (*DataFrame, error)
- func (df *DataFrame) SetCols(columnPositions []int, s *series.Series) (*DataFrame, error)
- func (df *DataFrame) SetIndex(col int) (*DataFrame, error)
- func (df *DataFrame) SetRow(row int, val interface{}) (*DataFrame, error)
- func (df *DataFrame) SetRows(rowPositions []int, val interface{}) (*DataFrame, error)
- func (df *DataFrame) Std() *series.Series
- func (df *DataFrame) String() string
- func (df *DataFrame) SubsetColumns(columnPositions []int) (*DataFrame, error)
- func (df *DataFrame) SubsetRows(rowPositions []int) (*DataFrame, error)
- func (df *DataFrame) Sum() *series.Series
- func (df *DataFrame) SwapColumns(i, j int) (*DataFrame, error)
- func (df *DataFrame) SwapRows(i, j int) (*DataFrame, error)
- func (df *DataFrame) Tail(n int) *DataFrame
- func (df *DataFrame) ToBool() *DataFrame
- func (df *DataFrame) ToDateTime() *DataFrame
- func (df *DataFrame) ToFloat64() *DataFrame
- func (df *DataFrame) ToInt64() *DataFrame
- func (df *DataFrame) ToInterface() *DataFrame
- func (df *DataFrame) ToString() *DataFrame
- func (df *DataFrame) Transpose() *DataFrame
- type Grouping
- func (g Grouping) First() *DataFrame
- func (g Grouping) Group(label string) *DataFrame
- func (g Grouping) Groups() []string
- func (g Grouping) Last() *DataFrame
- func (g Grouping) Len() int
- func (g Grouping) Max() *DataFrame
- func (g Grouping) Mean() *DataFrame
- func (g Grouping) Median() *DataFrame
- func (g Grouping) Min() *DataFrame
- func (g Grouping) SortedGroups() []string
- func (g Grouping) Std() *DataFrame
- func (g Grouping) String() string
- func (g Grouping) Sum() *DataFrame
- type InPlace
- func (ip InPlace) AppendCol(s *series.Series, colLabels ...string) error
- func (ip InPlace) AppendRow(val []interface{}, idxLabels ...interface{}) error
- func (ip InPlace) Convert(dataType string) error
- func (ip InPlace) DropCol(col int) error
- func (ip InPlace) DropCols(columnPositions []int) error
- func (ip InPlace) DropDuplicates()
- func (ip InPlace) DropNull(cols ...int)
- func (ip InPlace) DropRow(row int) error
- func (ip InPlace) DropRows(rowPositions []int) error
- func (ip InPlace) InsertCol(col int, s *series.Series, colLabels ...string) error
- func (ip InPlace) InsertRow(row int, val []interface{}, idxLabels ...interface{}) error
- func (ip InPlace) Len() int
- func (ip InPlace) ResetIndex(level int) error
- func (ip InPlace) Set(colLabel string, s *series.Series)
- func (ip InPlace) SetCol(col int, s *series.Series) error
- func (ip InPlace) SetCols(columnPositions []int, s *series.Series) error
- func (ip InPlace) SetIndex(col int) error
- func (ip InPlace) SetRow(row int, val interface{}) error
- func (ip InPlace) SetRows(rowPositions []int, val interface{}) error
- func (ip InPlace) String() string
- func (ip InPlace) SubsetColumns(columnPositions []int) error
- func (ip InPlace) SubsetRows(rowPositions []int) error
- func (ip InPlace) SwapColumns(i, j int)
- func (ip InPlace) SwapRows(i, j int)
- func (ip InPlace) ToBool()
- func (ip InPlace) ToDateTime()
- func (ip InPlace) ToFloat64()
- func (ip InPlace) ToInt64()
- func (ip InPlace) ToInterface()
- func (ip InPlace) ToString()
- type Index
- func (idx Index) AppendLevel(values interface{}, name string) error
- func (idx Index) At(row int, level int) interface{}
- func (idx Index) Convert(dataType string, level int) error
- func (idx Index) DropLevel(level int) error
- func (idx Index) DropNull(level int) error
- func (idx Index) Filter(level int, cmp func(interface{}) bool) []int
- func (idx Index) Flip(col int, level int) (*DataFrame, error)
- func (idx Index) InsertLevel(pos int, values interface{}, name string) error
- func (idx Index) Len() int
- func (idx Index) Less(i, j int) bool
- func (idx Index) Reindex(level int) error
- func (idx Index) RenameLevel(level int, name string) error
- func (idx Index) SelectName(name string) int
- func (idx Index) SelectNames(names []string) []int
- func (idx Index) Set(row int, level int, val interface{}) error
- func (idx Index) Sort(asc bool)
- func (idx Index) String() string
- func (idx Index) SubsetLevels(levelPositions []int) error
- func (idx Index) Swap(i, j int)
- func (idx Index) SwapLevels(i, j int) error
- func (idx Index) Values() [][]interface{}
- type Row
Examples ¶
- Columns (Valid_printer)
- DataFrame (Empty_df)
- DataFrame (MultiCol_col)
- DataFrame.Col
- Grouping (Method_list)
- InPlace (Method_list)
- Index (Valid_printer)
- New (Datetime)
- New (Empty_dataframe)
- New (Exceed_maxColumns_even)
- New (Exceed_maxColumns_odd)
- New (Exceed_maxRows_even)
- New (Exceed_maxRows_odd)
- New (Float64)
- New (Float64_colsNamed_repeat_allowed)
- New (Float64_colsNamed_repeat_resume)
- New (Float64_indexNamed_multicolNamed)
- New (MaxWidth_index)
- New (MaxWidth_value)
- New (No_interpolation)
- New (String_colsNamed)
- New (String_colsUnnamed)
- New (String_indexNamed)
- New (String_indexNamed_colsNamed)
- New (String_indexNamed_colsUnnamed)
- New (String_indexRepeated)
- New (String_indexRepeated_allowed)
- New (String_indexUnnamed)
- New (String_multiIndexNamed)
- New (String_multiIndexUnnamed)
- New (String_multicolNamed)
- New (String_multicolNamed_repeat)
- New (String_multicolUnnamed)
- New (String_multiindexNamed_colsNamed)
- New (String_multiindexNamed_multicolNamed)
- Row (Valid_printer)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
AppendLevel adds a new cols level to the end of the current cols and modifies the DataFrame in place.
func (Columns) At ¶
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 ¶
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 ¶
InsertLevel inserts a level into the cols and modifies the DataFrame in place.
func (Columns) RenameLevel ¶
RenameLevel renames an cols level in place but does not change anything if level is out of range.
func (Columns) Reorder ¶
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 ¶
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 ¶
SelectNames returns the integer positions of the cols levels with the supplied names.
func (Columns) SubsetLevels ¶
SubsetLevels modifies the DataFrame in place with only the specified cols levels.
func (Columns) SwapLevels ¶
SwapLevels swaps two column levels and modifies the cols in place.
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 New ¶
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) Col ¶
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) Convert ¶
Convert converts every series in a DataFrame to datatype and returns a new DataFrame.
func (*DataFrame) DropCol ¶
DropCol drops the column at the specified integer position and returns a new DataFrame.
func (*DataFrame) DropCols ¶
DropCols drops the column at the specified integer position and returns a new DataFrame.
func (*DataFrame) DropDuplicates ¶
DropDuplicates drops any rows containing duplicate index + DataFrame values and returns a new DataFrame.
func (*DataFrame) DropNull ¶
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 ¶
DropRow drops the row at the specified integer position and returns a new DataFrame.
func (*DataFrame) DropRows ¶
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 ¶
ExportToCSV exports the DataFrame to a CSV file.
func (*DataFrame) GroupBy ¶
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 ¶
GroupByIndex groups a DataFrame by one or more of its index levels. If no level is provided, all index levels are used.
func (*DataFrame) IndexLevels ¶
IndexLevels returns the number of index levels in the DataFrame.
func (*DataFrame) InsertCol ¶
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) Pivot ¶
Pivot transforms data into the desired form and calls aggFunc on the reshaped data.
func (*DataFrame) RenameCols ¶
RenameCols renames the columns at the specified labels.
func (*DataFrame) ResetIndex ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetCol sets all the values in the specified columns to val and returns a new DataFrame.
func (*DataFrame) SetCols ¶
SetCols sets all the values in the specified columns to val and returns a new DataFrame.
func (*DataFrame) SetIndex ¶
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 ¶
SetRow sets the value in the specified rows to val and returns a new DataFrame.
func (*DataFrame) SetRows ¶
SetRows sets all the values in the specified rows to val and returns a new DataFrame.
func (*DataFrame) SubsetColumns ¶
SubsetColumns subsets a DataFrame to include only the columns at supplied integer positions and returns a new DataFrame.
func (*DataFrame) SubsetRows ¶
SubsetRows subsets a DataFrame to include only the rows at supplied integer positions and returns a new DataFrame.
func (*DataFrame) SwapColumns ¶
SwapColumns swaps the selected rows and returns a new DataFrame.
func (*DataFrame) ToDateTime ¶
ToDateTime converts DataFrame values to time.Time and returns a new DataFrame.
func (*DataFrame) ToFloat64 ¶
ToFloat64 converts DataFrame values to float64 and returns a new DataFrame.
func (*DataFrame) ToInterface ¶
ToInterface converts DataFrame values to interface and returns a new DataFrame.
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) Group ¶
Group returns the DataFrame with the given group label, or an error if that label does not exist.
func (Grouping) Groups ¶
Groups returns all valid group labels in the Grouping, in their original group position.
func (Grouping) SortedGroups ¶
SortedGroups returns all valid group labels in the Grouping, sorted in alphabetical order.
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 ¶
AppendCol adds a row at a specified integer position and modifies the DataFrame in place. TODO take colLabels from series
func (InPlace) AppendRow ¶
AppendRow adds a row at a specified integer position and modifies the DataFrame in place.
func (InPlace) Convert ¶
Convert converts every series in a DataFrame to datatype and modifies the DataFrame in place.
func (InPlace) DropCol ¶
DropCol drops a column at a specified integer position and modifies the DataFrame in place.
func (InPlace) DropCols ¶
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 ¶
DropNull drops all null values and modifies the DataFrame in place. If an invalid column is provided, returns original DataFrame.
func (InPlace) DropRow ¶
DropRow drops the row at the specified integer position and modifies the DataFrame in place.
func (InPlace) DropRows ¶
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 ¶
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 ¶
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 ¶
Len returns the length of the underlying DataFrame (required by Sort interface)
func (InPlace) ResetIndex ¶
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 ¶
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 ¶
SetCol sets the values in the specified column to val and modifies the DataFrame in place.
func (InPlace) SetCols ¶
SetCols sets the values in the specified columns to val and modifies the DataFrame in place.
func (InPlace) SetIndex ¶
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 ¶
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 ¶
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) SubsetColumns ¶
SubsetColumns subsets a DataFrame to include only the columns at supplied integer positions and modifies the DataFrame in place.
func (InPlace) SubsetRows ¶
SubsetRows subsets a DataFrame to include only the rows at supplied integer positions and modifies the DataFrame in place.
func (InPlace) SwapColumns ¶
SwapColumns swaps the selected columns 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.
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 ¶
AppendLevel adds a new index level to the end of the current index and modifies the DataFrame in place.
func (Index) At ¶
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) DropLevel ¶
DropLevel drops the specified index level and modifies the DataFrame in place.
func (Index) DropNull ¶
DropNull drops null index values at the index level specified and modifies the DataFrame in place.
func (Index) Filter ¶
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 ¶
Flip replaces the DataFrame values at the supplied column with the labels at the supplied index level, and vice versa.
func (Index) InsertLevel ¶
InsertLevel inserts a level into the index and modifies the DataFrame in place.
func (Index) Less ¶
Less compares two elements and returns true if the first is less than the second. Required by Sort interface.
func (Index) RenameLevel ¶
RenameLevel renames an index level in place but does not change anything if level is out of range.
func (Index) SelectName ¶
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 ¶
SelectNames returns the integer positions of the index levels with the supplied names.
func (Index) Set ¶
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) SubsetLevels ¶
SubsetLevels modifies the DataFrame in place with only the specified index levels.
func (Index) Swap ¶
Swap swaps two labels at index level 0 and modifies the index in place. Required by Sort interface.
func (Index) SwapLevels ¶
SwapLevels swaps two levels in the index and modifies the DataFrame in place.
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]