godf

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 17 Imported by: 0

README

godf

Go Reference

A simple dataframe handler for golang, inspired by pandas from python. I used @jedib0t's go-pretty to render the table.

It can handle simple data manipulation such as :

  • One hot encoding
  • Sorting
  • Shuffling data
  • Filtering

Install

go get -u github.com/kevinmtanadi/godf

Usage

Basic Usage
x := []float64{0.1, 0.2, 0.3, 0.4, 0.5}
y := []float64{1.1, 1.2, 1.3, 1.4, 1.5}
z := []float64{21, 22, 23, 24, 25}

df := godf.DataFrame(map[string]interface{}{
  "x": x,
  "y": y,
  "z": z,
})

df.Show()
┌───┬─────┬─────┬────┐
│ # │   X │   Y │  Z │
├───┼─────┼─────┼────┤
│ 1 │ 0.1 │ 1.1 │ 21 │
│ 2 │ 0.2 │ 1.2 │ 22 │
│ 3 │ 0.3 │ 1.3 │ 23 │
│ 4 │ 0.4 │ 1.4 │ 24 │
│ 5 │ 0.5 │ 1.5 │ 25 │
└───┴─────┴─────┴────┘
Read CSV File
df := godf.ReadCSV("data.csv")

df.Show()
License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoCast

func AutoCast(data interface{}) any

func Average added in v0.1.5

func Average(d *dataframe)

func CastArrayFloat64

func CastArrayFloat64(data interface{}) []float64

func CastArrayInt

func CastArrayInt(data interface{}) []int

func CastArrayString

func CastArrayString(data interface{}) []string

func CastFloat64

func CastFloat64(data interface{}) float64

func CastHeaders

func CastHeaders(headers []string) []interface{}

func CastInt

func CastInt(data interface{}) int

func CastString

func CastString(data interface{}) string

func DataFrame

func DataFrame(data map[string]interface{}, opts ...DataframeOption) *dataframe

DataFrame initializes and returns a dataframe

This function takes a map[string]interface{} as a variable where the string will be the header name and the interface{} will be the contained data

Returns a pointer to the dataframe

func GetDatatype added in v0.0.5

func GetDatatype(data interface{}) reflect.Kind

func Median added in v0.1.5

func Median(d *dataframe)

func ReadCSV

func ReadCSV(filename string) *dataframe

Read CSV and parse it into a dataframe

Support reading from local file or URL

func Zero added in v0.1.5

func Zero(d *dataframe)

Types

type DataframeOption added in v0.0.6

type DataframeOption struct {
	StringLimit int
	// contains filtered or unexported fields
}

type Eq added in v0.0.5

type Eq map[string]interface{}

Eq filter rows where a data in the given column is equal to given value

Example of usage:
df.Where(Eq{"x": 5})
will only get data with x = 5

type Filter added in v0.0.5

type Filter interface {
	// contains filtered or unexported methods
}

type GT added in v0.0.5

type GT map[string]interface{}

GT filter rows where a data in the given column is greater than the given value

Example of usage:
df.Where(GT{"x": 5})
will only get data with x > 5

type GTE added in v0.0.5

type GTE map[string]interface{}

GTE filter rows where a data in the given column is greater than or equal to the given value

Example of usage:
df.Where(GTE{"x": 5})
will only get data with x >= 5

type In added in v0.0.5

type In map[string]interface{}

In filter all data which value is in the given slice

Example of usage:
df.Where(In{"x": []int{1, 2, 3, 4}})
will only get data with x = [1, 2, 3, 4]

type LT added in v0.0.5

type LT map[string]interface{}

LT filter rows where a data in the given column is less than the given value

Example of usage:
df.Where(LT{"x": 5})
will only get data with x < 5

type LTE added in v0.0.5

type LTE map[string]interface{}

LTE filter rows where a data in the given column is less than or equal to the given value

Example of usage:
df.Where(LTE{"x": 5})
will only get data with x <= 5

type NotEq added in v0.0.5

type NotEq map[string]interface{}

NotEq filter rows where a data in the given column is not equal to given value

Example of usage:
df.Where(NotEq{"x": 5})
will get all data except the data with x = 5

type Preprocessing added in v0.0.6

type Preprocessing interface {
	Standardize()
	Normalize()
	OneHotEncode()
}

Jump to

Keyboard shortcuts

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