Documentation ¶
Overview ¶
Package dataframe implements data frame.
Index ¶
- Variables
- func DurationAscendingFunc(idx int) func(row1, row2 *[]string) bool
- func DurationDescendingFunc(idx int) func(row1, row2 *[]string) bool
- func Float64AscendingFunc(idx int) func(row1, row2 *[]string) bool
- func Float64DescendingFunc(idx int) func(row1, row2 *[]string) bool
- func StringAscendingFunc(idx int) func(row1, row2 *[]string) bool
- func StringDescendingFunc(idx int) func(row1, row2 *[]string) bool
- type ByDurationAscending
- type ByDurationDescending
- type ByFloat64Ascending
- type ByFloat64Descending
- type ByStringAscending
- type ByStringDescending
- type Column
- type DATA_TYPE
- type Frame
- type GoTime
- func (gt GoTime) Copy() Value
- func (gt GoTime) Duration() (time.Duration, bool)
- func (gt GoTime) EqualTo(v Value) bool
- func (gt GoTime) Float64() (float64, bool)
- func (gt GoTime) Int64() (int64, bool)
- func (gt GoTime) IsNil() bool
- func (gt GoTime) String() (string, bool)
- func (gt GoTime) Time(layout string) (time.Time, bool)
- func (gt GoTime) Uint64() (uint64, bool)
- type LessFunc
- type MultiSorter
- type SortOption
- type SortType
- type String
- func (s String) Copy() Value
- func (s String) Duration() (time.Duration, bool)
- func (s String) EqualTo(v Value) bool
- func (s String) Float64() (float64, bool)
- func (s String) Int64() (int64, bool)
- func (s String) IsNil() bool
- func (s String) String() (string, bool)
- func (s String) Time(layout string) (time.Time, bool)
- func (s String) Uint64() (uint64, bool)
- type Value
Constants ¶
This section is empty.
Variables ¶
var TimeDefaultLayout = "2006-01-02 15:04:05 -0700 MST"
TimeDefaultLayout is used to parse time.Time.
Functions ¶
func DurationAscendingFunc ¶
func DurationDescendingFunc ¶
func Float64AscendingFunc ¶
func Float64DescendingFunc ¶
func StringAscendingFunc ¶
func StringDescendingFunc ¶
Types ¶
type ByDurationAscending ¶
type ByDurationAscending []Value
func (ByDurationAscending) Len ¶
func (vs ByDurationAscending) Len() int
func (ByDurationAscending) Less ¶
func (vs ByDurationAscending) Less(i, j int) bool
func (ByDurationAscending) Swap ¶
func (vs ByDurationAscending) Swap(i, j int)
type ByDurationDescending ¶
type ByDurationDescending []Value
func (ByDurationDescending) Len ¶
func (vs ByDurationDescending) Len() int
func (ByDurationDescending) Less ¶
func (vs ByDurationDescending) Less(i, j int) bool
func (ByDurationDescending) Swap ¶
func (vs ByDurationDescending) Swap(i, j int)
type ByFloat64Ascending ¶
type ByFloat64Ascending []Value
func (ByFloat64Ascending) Len ¶
func (vs ByFloat64Ascending) Len() int
func (ByFloat64Ascending) Less ¶
func (vs ByFloat64Ascending) Less(i, j int) bool
func (ByFloat64Ascending) Swap ¶
func (vs ByFloat64Ascending) Swap(i, j int)
type ByFloat64Descending ¶
type ByFloat64Descending []Value
func (ByFloat64Descending) Len ¶
func (vs ByFloat64Descending) Len() int
func (ByFloat64Descending) Less ¶
func (vs ByFloat64Descending) Less(i, j int) bool
func (ByFloat64Descending) Swap ¶
func (vs ByFloat64Descending) Swap(i, j int)
type ByStringAscending ¶
type ByStringAscending []Value
func (ByStringAscending) Len ¶
func (vs ByStringAscending) Len() int
func (ByStringAscending) Less ¶
func (vs ByStringAscending) Less(i, j int) bool
func (ByStringAscending) Swap ¶
func (vs ByStringAscending) Swap(i, j int)
type ByStringDescending ¶
type ByStringDescending []Value
func (ByStringDescending) Len ¶
func (vs ByStringDescending) Len() int
func (ByStringDescending) Less ¶
func (vs ByStringDescending) Less(i, j int) bool
func (ByStringDescending) Swap ¶
func (vs ByStringDescending) Swap(i, j int)
type Column ¶
type Column interface { // Count returns the number of rows of the Column. Count() int // Header returns the header of the Column. Header() string // Rows returns all the data in string slice. Rows() []string // Uint64s returns all the data in int64 slice. Uint64s() ([]uint64, bool) // Int64s returns all the data in int64 slice. Int64s() ([]int64, bool) // Float64s returns all the data in float64 slice. Float64s() ([]float64, bool) // Times returns all the data in time.Time slice. Times(layout string) ([]time.Time, bool) // UpdateHeader updates the header of the Column. UpdateHeader(header string) // Value returns the Value in the row. It returns error if the row // is out of index range. Value(row int) (Value, error) // Set overwrites the value Set(row int, v Value) error // FindFirst finds the first Value, and returns the row number. // It returns -1 and false if the value does not exist. FindFirst(v Value) (int, bool) // FindLast finds the last Value, and returns the row number. // It returns -1 and false if the value does not exist. FindLast(v Value) (int, bool) // Front returns the first row Value. Front() (Value, bool) // FrontNonNil returns the first non-nil Value from the first row. FrontNonNil() (Value, bool) // Back returns the last row Value. Back() (Value, bool) // BackNonNil returns the first non-nil Value from the last row. BackNonNil() (Value, bool) // PushFront adds a Value to the front of the Column. // This does not prevent inserting wrong data types. // Assumes all data are string. PushFront(v Value) int // PushFrontTyped adds a Value to the front of the Column. // It returns error if the value doesn't match the type of the column. PushFrontTyped(v interface{}) (int, error) // PushBack appends the Value to the Column. // This does not prevent inserting wrong data types. // Assumes all data are string. PushBack(v Value) int // PushBackTyped appends the Value to the Column. // It returns error if the value doesn't match the type of the column. PushBackTyped(v interface{}) (int, error) // Delete deletes a row by index. Delete(row int) (Value, error) // Deletes deletes rows by index [start, end). Deletes(start, end int) error // Keep keeps the rows by index [start, end). Keep(start, end int) error // PopFront deletes the value at front. PopFront() (Value, bool) // PopBack deletes the last value. PopBack() (Value, bool) // Appends adds the Value to the Column until it reaches the target size. Appends(v Value, targetSize int) error // Copy deep-copies a column. Copy() Column // SortByStringAscending sorts Column in string ascending order. SortByStringAscending() // SortByStringDescending sorts Column in string descending order. SortByStringDescending() // SortByFloat64Ascending sorts Column in number(float) ascending order. SortByFloat64Ascending() // SortByFloat64Descending sorts Column in number(float) descending order. SortByFloat64Descending() // SortByDurationAscending sorts Column in time.Duration ascending order. SortByDurationAscending() // SortByDurationDescending sorts Column in time.Duration descending order. SortByDurationDescending() }
Column represents column-based data.
func NewColumnTyped ¶
NewColumnTyped creates a new Column with data type.
type DATA_TYPE ¶
type DATA_TYPE uint8
DATA_TYPE defines dataframe data types.
func ReflectTypeOf ¶
func ReflectTypeOf(v interface{}) DATA_TYPE
ReflectTypeOf returns the DATA_TYPE.
type Frame ¶
type Frame interface { // Headers returns the slice of headers in order. Header name is unique among its Frame. Headers() []string // AddColumn adds a Column to Frame. AddColumn(c Column) error // Column returns the Column by its header name. Column(header string) (Column, error) // Columns returns all Columns. Columns() []Column // Count returns the number of Columns in the Frame. Count() int // UpdateHeader updates the header name of a Column. UpdateHeader(origHeader, newHeader string) error // MoveColumn moves the column right before the target index. MoveColumn(header string, target int) error // DeleteColumn deletes the Column by its header. DeleteColumn(header string) bool // CSV saves the Frame to a CSV file. CSV(fpath string) error // CSVHorizontal saves the Frame to a CSV file // in a horizontal way. The first column is header. // And data are aligned from left to right. CSVHorizontal(fpath string) error // Rows returns the header and data slices. Rows() ([]string, [][]string) // Sort sorts the Frame. Sort(header string, st SortType, so SortOption) error }
Frame contains data.
func NewFromCSV ¶
NewFromCSV creates a new Frame from CSV. Pass 'nil' header if first row is used as header strings. Pass 'non-nil' header if the data starts from the first row, without header strings.
func NewFromColumns ¶
NewFromColumns combines multiple columns into one data frame. If zero Value is not nil, it makes all columns have the same row number by inserting zero values where the row number is short compared to the one with the msot row number. The columns are deep-copied to the Frame.
type MultiSorter ¶
type MultiSorter struct {
// contains filtered or unexported fields
}
MultiSorter implements the Sort interface, sorting the two dimensional string slices within.
func SortBy ¶
func SortBy(rows [][]string, lesses ...LessFunc) *MultiSorter
SortBy returns a multiSorter that sorts using the less functions
func (*MultiSorter) Less ¶
func (ms *MultiSorter) Less(i, j int) bool
Less is part of sort.Interface.
func (*MultiSorter) Sort ¶
func (ms *MultiSorter) Sort(rows [][]string)
Sort sorts the rows according to LessFunc.
type SortOption ¶
type SortOption int
const ( SortOption_Ascending SortOption = iota SortOption_Descending )
type Value ¶
type Value interface { // String parses Value to string. It returns false if not possible. String() (string, bool) // Int64 parses Value to int64. It returns false if not possible. Int64() (int64, bool) // Uint64 parses Value to uint64. It returns false if not possible. Uint64() (uint64, bool) // Float64 parses Value to float64. It returns false if not possible. Float64() (float64, bool) // Time parses Value to time.Time based on the layout. It returns false if not possible. Time(layout string) (time.Time, bool) // Duration parses Value to time.Duration. It returns false if not possible. Duration() (time.Duration, bool) // IsNil returns true if the Value is nil. IsNil() bool // EqualTo returns true if the Value is equal to v. EqualTo(v Value) bool // Copy copies Value. Copy() Value }
Value represents the value in data frame.
func NewStringValue ¶
func NewStringValue(v interface{}) Value
NewStringValue takes any interface and returns Value.
func NewTimeValue ¶
func NewTimeValue(v interface{}) Value
NewTimeValue takes any interface and returns Value.