dataframe

package module
v0.0.0-...-008fc24 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2017 License: Apache-2.0 Imports: 7 Imported by: 16

README

dataframe Go Report Card Build Status Godoc

Package dataframe implements data frame.

Documentation

Overview

Package dataframe implements data frame.

Index

Constants

This section is empty.

Variables

View Source
var TimeDefaultLayout = "2006-01-02 15:04:05 -0700 MST"

TimeDefaultLayout is used to parse time.Time.

Functions

func DurationAscendingFunc

func DurationAscendingFunc(idx int) func(row1, row2 *[]string) bool

func DurationDescendingFunc

func DurationDescendingFunc(idx int) func(row1, row2 *[]string) bool

func Float64AscendingFunc

func Float64AscendingFunc(idx int) func(row1, row2 *[]string) bool

func Float64DescendingFunc

func Float64DescendingFunc(idx int) func(row1, row2 *[]string) bool

func StringAscendingFunc

func StringAscendingFunc(idx int) func(row1, row2 *[]string) bool

func StringDescendingFunc

func StringDescendingFunc(idx int) func(row1, row2 *[]string) bool

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 NewColumn

func NewColumn(hd string) Column

NewColumn creates a new Column.

func NewColumnTyped

func NewColumnTyped(hd string, tp DATA_TYPE) Column

NewColumnTyped creates a new Column with data type.

type DATA_TYPE

type DATA_TYPE uint8

DATA_TYPE defines dataframe data types.

const (
	// STRING represents Go string or bytes.
	STRING DATA_TYPE = iota

	// TIME represents Go time.Time type.
	TIME
)

func ReflectTypeOf

func ReflectTypeOf(v interface{}) DATA_TYPE

ReflectTypeOf returns the DATA_TYPE.

func (DATA_TYPE) String

func (dt DATA_TYPE) String() string

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 New

func New() Frame

New returns a new Frame.

func NewFromCSV

func NewFromCSV(header []string, fpath string) (Frame, error)

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

func NewFromColumns(zero Value, cols ...Column) (Frame, error)

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.

func NewFromRows

func NewFromRows(header []string, rows [][]string) (Frame, error)

NewFromRows creates Frame from rows. 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.

type GoTime

type GoTime time.Time

GoTime defines time data types.

func (GoTime) Copy

func (gt GoTime) Copy() Value

func (GoTime) Duration

func (gt GoTime) Duration() (time.Duration, bool)

func (GoTime) EqualTo

func (gt GoTime) EqualTo(v Value) bool

func (GoTime) Float64

func (gt GoTime) Float64() (float64, bool)

func (GoTime) Int64

func (gt GoTime) Int64() (int64, bool)

func (GoTime) IsNil

func (gt GoTime) IsNil() bool

func (GoTime) String

func (gt GoTime) String() (string, bool)

func (GoTime) Time

func (gt GoTime) Time(layout string) (time.Time, bool)

func (GoTime) Uint64

func (gt GoTime) Uint64() (uint64, bool)

type LessFunc

type LessFunc func(p1, p2 *[]string) bool

LessFunc compares between two string slices.

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) Len

func (ms *MultiSorter) Len() int

Len is part of sort.Interface.

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.

func (*MultiSorter) Swap

func (ms *MultiSorter) Swap(i, j int)

Swap is part of sort.Interface.

type SortOption

type SortOption int
const (
	SortOption_Ascending SortOption = iota
	SortOption_Descending
)

type SortType

type SortType int
const (
	SortType_String SortType = iota
	SortType_Float64
	SortType_Duration
)

type String

type String string

String defines string data types.

func (String) Copy

func (s String) Copy() Value

func (String) Duration

func (s String) Duration() (time.Duration, bool)

func (String) EqualTo

func (s String) EqualTo(v Value) bool

func (String) Float64

func (s String) Float64() (float64, bool)

func (String) Int64

func (s String) Int64() (int64, bool)

func (String) IsNil

func (s String) IsNil() bool

func (String) String

func (s String) String() (string, bool)

func (String) Time

func (s String) Time(layout string) (time.Time, bool)

func (String) Uint64

func (s String) Uint64() (uint64, bool)

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 NewStringValueNil

func NewStringValueNil() Value

NewStringValueNil returns an empty value.

func NewTimeValue

func NewTimeValue(v interface{}) Value

NewTimeValue takes any interface and returns Value.

func NewTimeValueNil

func NewTimeValueNil() Value

NewTimeValueNil returns an empty value.

func ToValue

func ToValue(v interface{}) Value

ToValue converts to Value.

Jump to

Keyboard shortcuts

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