dataframe

package
v0.0.0-...-04a4f9f Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: GPL-3.0 Imports: 5 Imported by: 31

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dataframe

type Dataframe struct {
	Header map[string]int

	Index map[string]int

	Rows [][]string
	// contains filtered or unexported fields
}

Dataframe stores data as a two-dimensional string slice with header and index as maps or named indeces.

func FromFile

func FromFile(infile string, column interface{}) (*Dataframe, error)

FromFile creates a dataframe and loads in data from the given input file. The first row is assumed to be the header.

func FromSlice

func FromSlice(rows [][]string, column interface{}) (*Dataframe, error)

FromSlice creates a new dataframe and loads data from the given slice. The first row is assumed to be the header.

func NewDataFrame

func NewDataFrame(column interface{}) (*Dataframe, error)

NewDataFrame returns an empty dataframe struct.

func (*Dataframe) AddColumn

func (d *Dataframe) AddColumn(name, null string)

AddColumn adds a new column with the given name to the end of the dataframe and stores the given null value in each row.

func (*Dataframe) AddRow

func (d *Dataframe) AddRow(row []string) error

AddRow adds a string slice to dataframe and stores the index value in Index if using.

func (*Dataframe) Clone

func (d *Dataframe) Clone() *Dataframe

Clone returns a copy of the dataframe's structure. Specifically, it returns an empty dataframe with the same header and index column name.

func (*Dataframe) Compare

func (d *Dataframe) Compare(n *Dataframe) error

Compare returns an error if target dataframe is not equal to d (for testing).

func (*Dataframe) Copy

func (d *Dataframe) Copy() *Dataframe

Copy returns a deep copy of the dataframe.

func (*Dataframe) DeleteColumn

func (d *Dataframe) DeleteColumn(col interface{}) error

DeleteColumn removes the given column from dataframe.

func (*Dataframe) DeleteRow

func (d *Dataframe) DeleteRow(idx interface{}) error

DeleteRow removes the given row from dataframe.

func (*Dataframe) Dimensions

func (d *Dataframe) Dimensions() (int, int)

Dimensions returns row and column lengths (respectively).

func (*Dataframe) Extend

func (d *Dataframe) Extend(n *Dataframe) error

Extend appends rows from n to the current dataframe. Rows with redundant index values will be skipped.

func (*Dataframe) FormatHeader

func (d *Dataframe) FormatHeader(sep string) string

FormatHeader formats header for writing. Prepends index name if needed.

func (*Dataframe) GetCell

func (d *Dataframe) GetCell(idx interface{}, col interface{}) (string, error)

GetCell returns the value of the given cell from dataframe.

func (*Dataframe) GetCellFloat

func (d *Dataframe) GetCellFloat(idx interface{}, col interface{}) (float64, error)

GetCellFloat returns the value of the given cell as float64. Returns an error if it cannot be converted.

func (*Dataframe) GetCellInt

func (d *Dataframe) GetCellInt(idx interface{}, col interface{}) (int, error)

GetCellInt returns the value of the given cell as int. Returns an error if it cannot be converted.

func (*Dataframe) GetColumn

func (d *Dataframe) GetColumn(col interface{}) ([]string, error)

GetColumn returns the given column from dataframe.

func (*Dataframe) GetColumnUnique

func (d *Dataframe) GetColumnUnique(col interface{}) ([]string, error)

GetColumnUnique returns all unique values from the given column.

func (*Dataframe) GetHeader

func (d *Dataframe) GetHeader() []string

GetHeader returns the header as string slice.

func (*Dataframe) GetIndex

func (d *Dataframe) GetIndex() []string

GetIndex returns index as string slice.

func (*Dataframe) GetMetaData

func (d *Dataframe) GetMetaData() string

Returns metadata value.

func (*Dataframe) GetRow

func (d *Dataframe) GetRow(idx interface{}) ([]string, error)

GetRow returns given row from dataframe. Does not insert index value.

func (*Dataframe) Iterate

func (d *Dataframe) Iterate() <-chan *Series

Iterate returns each row as a series.

func (*Dataframe) Length

func (d *Dataframe) Length() int

Length returns the number of rows.

func (*Dataframe) Print

func (d *Dataframe) Print()

Print writes the dataframe to the screen

func (*Dataframe) RenameColumn

func (d *Dataframe) RenameColumn(o, n string) error

RenameColumn changes the name of column o to n. Returns an error if o is not found.

func (*Dataframe) RenameRow

func (d *Dataframe) RenameRow(o, n string) error

RenameRow changes the name of row o to n. Returns an error if o is not found.

func (*Dataframe) SetHeader

func (d *Dataframe) SetHeader(row []string) error

SetHeader converts the given row to header map.

func (*Dataframe) SetMetaData

func (d *Dataframe) SetMetaData(v string)

Stores metadata value.

func (*Dataframe) SliceRow

func (d *Dataframe) SliceRow(idx interface{}, start interface{}, end interface{}) ([]string, error)

SliceRow returns a slice of the given row between start and end (not including the value at end).

func (*Dataframe) ToCSV

func (d *Dataframe) ToCSV(outfile string)

ToCSV writes dataframe to csv with header and index inderted.

func (*Dataframe) ToSeries

func (d *Dataframe) ToSeries(idx interface{}) *Series

ToSeries returns row at given index to a series

func (*Dataframe) ToSlice

func (d *Dataframe) ToSlice() [][]string

ToSlice returns dataframe as a two-dimensional string slice (inserts index values if needed but does not include header).

func (*Dataframe) UpdateCell

func (d *Dataframe) UpdateCell(idx interface{}, col interface{}, v string) error

UpdateCell replaces the value in a given cell with v.

type Series

type Series struct {

	// Encapsulates error so it can be returned through channel
	Error error
	// Same as dataframe header
	Header map[string]int
	// Interger index of row in Rows slice
	Index int
	// Name of row if index map is set
	Name string
	// Copy of row from dataframe at index
	Row []string
	// contains filtered or unexported fields
}

func (*Series) GetCell

func (s *Series) GetCell(col string) (string, error)

GetCell returns cell from the given column.

func (*Series) GetCellFloat

func (s *Series) GetCellFloat(col string) (float64, error)

GetCellFloat returns the value of the given cell as float64. Returns an error if it cannot be converted.

func (*Series) GetCellInt

func (s *Series) GetCellInt(col string) (int, error)

GetCellInt returns the value of the given cell as int. Returns an error if it cannot be converted.

func (*Series) ToSlice

func (s *Series) ToSlice() []string

ToSlice returns series a stirng slice and inserts index value if needed.

func (*Series) UpdateCell

func (s *Series) UpdateCell(col, val string) error

UpdateCell updates col to val. Returns error if column name is not in header.

Jump to

Keyboard shortcuts

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