godf

module
v0.0.0-...-460a440 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT

README

Go DF

GoDF is an implementation, in go, of a DataFrame structure. DataFrame is a structure to represents bidimensional data, as a table.

Usage

Data from a struct

You can define the DataFrame data from the Go struct.

// DataFrame struct
type Df struct {
	A int      `colName:"column1"`
	B float32  `colName:"column2"`
	// private field. It will not export.
	c float32    
	// public field, but it has not the tag colName. It will not export.
	C float32    
	D string  `colName:"column3"`
}

// Data for the DataFrame.
data := []Df{
	{1, 1.1, 1.1, "test 1"},
	{2, 2.2, 2.2, "test 2"},
}

// Make the dataframe.
df, err := NewDataFrameFromStruct(data)

Only it can export, from the Go struct, fields with valid types:

  • int
  • int64
  • int32
  • int16
  • int8
  • uint
  • uint64
  • uint32
  • uint16
  • uint8
  • float64
  • float32
  • complex64
  • complex128
  • string

Define you custom type

Also it can create custom types, implementing the interface ValueTypes

  • IntType
  • UintType
  • FloatType
  • ComplexType
  • StringType
// Custom struct
type Thousand struct {
	value float64
}

// Implements the FloatType interface
func (t *Thousand) String() {
	return fmt.Sprintf("%g", f.v)
}

func (f simpleFloatType) Value() float64 {
	return f.v / 1000
}

func (f simpleFloatType) Compare(v float64) Comparers {
	if f.v == v {
		return EQUAL
	} else if f.v < v {
		return LESS
	}

	return GREAT
}

// DataFrame struct
type MyStruct {
	Country string `colname:"country"`
	// Custom type
	People Thousand `colname:"people"`
}

df, _ := NewDataFrameFromStruct(data)

Documentation

Offical documentation

wip...

Directories

Path Synopsis
* Package dataframe provides a DatFrame structure for handle table data.
* Package dataframe provides a DatFrame structure for handle table data.

Jump to

Keyboard shortcuts

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