Help us shape the future of Go! Take the 2026 Go Developer Survey

dataframe

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: BSD-3-Clause Imports: 21 Imported by: 0

README

dataframe

Labelled, columnar tables in pure Go (CGO=0): Series, DataFrame and Index, with selection, missing data, group-by, joins, reshaping, time series, a fast CSV reader, Arrow IPC and Parquet, notebook display and plots. Numeric columns are go-ndarray arrays, handed out without copying.

pandas is the behavioural reference: the operations below give pandas' answers (values, dtypes, index, row order), checked against pandas 3.0 on 173 recorded cases; the differences that remain are deliberate and listed in docs/design.md.

import "github.com/go-dataframe/dataframe"

df := dataframe.Must(dataframe.ReadCSVFile("weather.csv", dataframe.CSVParseDates("date")))
fmt.Println(df.Head(5))

DataFrame, Series and Index have Display(), so a go-notebook cell shows them as pandas does (text, and an HTML table).

From pandas

pandas dataframe
pd.DataFrame({"a": [1, 2], "b": ["x", "y"]}) dataframe.New(dataframe.Col("a", []int{1, 2}), dataframe.Col("b", []string{"x", "y"}))
pd.Series([1.5, None]) dataframe.NewSeries("", []any{1.5, nil})
pd.read_csv(path, usecols=..., nrows=..., parse_dates=[...]) dataframe.ReadCSVFile(path, dataframe.CSVUseCols(...), dataframe.CSVNRows(n), dataframe.CSVParseDates(...))
df.to_csv(path) df.WriteCSVFile(path)
pd.read_parquet(p), df.to_parquet(p) parquetio.ReadParquetFile(p), parquetio.WriteParquetFile(p, df)
pd.read_feather(p), df.to_feather(p) arrowio.ReadFeather(p), arrowio.WriteFeather(p, df)
df.head(), df.tail(3) df.Head(5), df.Tail(3)
df.shape, df.columns, df.dtypes, df.index df.Shape(), df.Columns(), df.DTypes(), df.Index()
df["a"], df[["a", "b"]] df.Column("a"), df.Select("a", "b")
df.values, s.values df.Values(), s.Values() (*ndarray.Array)
df.iloc[0:5], df.iloc[[0, 2], 1:3] df.Iloc(dataframe.Slice(0, 5)), df.Iloc(dataframe.Pos(0, 2), dataframe.Slice(1, 3))
df.loc["a":"c", ["x"]] df.Loc(dataframe.LabelRange("a", "c"), "x")
df[df.x > 0] df.Filter(dataframe.Must(x.Gt(0)))
df.query("x > 0 and s in ['a', 'b']") df.Query("x > 0 and s in ['a', 'b']")
df.set_index("k"), df.reset_index() df.SetIndex("k"), df.ResetIndex(false)
df.sort_values(["a", "b"], ascending=[True, False]) df.SortValues([]string{"a", "b"}, true, false)
df.sort_index(), df.reindex(labels) df.SortIndex(true), df.Reindex(labels)
df.dropna(), df.fillna(0), df.isna() df.DropNA(), df.FillNA(0), df.IsNA()
df.sum(), df.mean(), df.describe() df.Sum(), df.Mean(), df.Describe()
df.round(2), df.T, df.astype({"a": "float64"}) df.Round(2), df.T(), df.AsType(map[string]dataframe.DType{"a": dataframe.Float64})
df.rename(columns={"a": "b"}), df.copy() df.Rename(map[string]string{"a": "b"}), df.Copy()
df.a + df.b (aligned on the index) a.Add(b)
s.apply(f), df.apply(f, axis=1) s.Map(f), df.Apply("name", f)
df.groupby(["k1", "k2"]).sum() g, _ := df.GroupBy("k1", "k2"); g.Sum()
df.groupby("k").agg(x=("x", "mean")) g.Agg(dataframe.Agg("x", "mean"))
pd.concat([a, b]), pd.concat([a, b], axis=1) dataframe.Concat(a, b), dataframe.ConcatWith(dataframe.ConcatOptions{Axis: 1}, a, b)
pd.merge(l, r, on="k", how="left") dataframe.Merge(l, r, dataframe.MergeOptions{On: []string{"k"}, How: "left"})
df.pivot(...), df.pivot_table(...), df.melt(...) df.Pivot(...), df.PivotTable(...), df.Melt(...)
df.stack(), s.unstack() df.Stack(), s.Unstack()
pd.to_datetime(s), pd.Timestamp("2024-01-01") dataframe.ToDatetime(s), dataframe.Timestamp("2024-01-01")
df.resample("D").sum() r, _ := df.Resample("D"); r.Sum()
df.to_period("M"), s.dt.year df.ToPeriod("M"), d, _ := s.Dt(); d.Year()
s.shift(1), s.diff(), s.cumsum(), s.rolling(7).mean() s.Shift(1), s.Diff(1), s.CumSum(), r, _ := s.Rolling(7); r.Mean()
df.plot(), df.plot.bar(), df.hist(), df.plot.scatter(x, y) dfplot.Line(df), dfplot.Bar(df), dfplot.Hist(df, 10), dfplot.Scatter(df, x, y)

Fallible calls return (value, error); dataframe.Must unwraps one in a notebook cell. Every value is immutable: operations return new frames that share the columns they did not change.

Speed and memory

Medians of interleaved runs, 10⁷ rows, Apple M4 Max, on a shared host under load (load average 13–18; see docs/perf.md for the method, a second run under heavier load, 10⁶ rows, and Arrow/Parquet). Milliseconds:

operation go-dataframe pandas 3.0 polars
read_csv (5 mixed columns) 407 4220 (C parser) / 525 (pyarrow) 360
read_csv, dates parsed 362 5900 417
sort_values (stable, float key) 446 973 298
merge (inner, int key) 161 234 55
groupby("int key").sum() 88 103 69
df[df.x > 0.5] 74 75 20
groupby("str key").sum() 222 204 60

go-dataframe is faster than pandas on all of these but the string-key group-by, which is at parity (CSV by about 10x, sorting by 2x); polars remains faster on most of them. Memory is at par with pandas for numeric columns but worse for strings (a Go []string costs 16 bytes a value; pandas 3 and polars use Arrow-style string buffers): the benchmark table takes 400 MB here, 349 MB in pandas, 269 MB in polars.

Packages

  • dataframe — the core: Series, DataFrame, Index, CSV, display.
  • dataframe/arrowio — Arrow IPC (file/Feather and stream) and Arrow record conversion, over apache/arrow-go.
  • dataframe/parquetio — Parquet, over apache/arrow-go.
  • dataframe/dfplot — plots with go-plot.

Verification

  • testdata/gen_fixtures.py records pandas' answers (values, dtypes, index, NA handling, sort stability, group-by order, merge row order, repr text) for 173 cases; TestPandasFixtures replays them.
  • A corpus of 47 awkward CSV files (69 option sets) is compared with pandas' parse, and Arrow and Parquet files written by pandas/pyarrow are read back and compared.
  • 100% statement coverage of the whole module under the race detector, on Linux, macOS and Windows; tests also run natively on amd64/arm64 and under qemu on riscv64, loong64, ppc64le and s390x (big-endian).

Licence

BSD 3-Clause, see LICENSE.

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/go-dataframe/dataframe"
)

func main() {
	df := dataframe.Must(dataframe.New(
		dataframe.Col("city", []string{"Lyon", "Paris", "Nice", "Paris", "Lyon"}),
		dataframe.Col("year", []int{2023, 2023, 2024, 2024, 2024}),
		dataframe.Col("rain", []float64{830.5, 640.2, 760.1, 598.7, 810.0}),
	))
	fmt.Println(df.Head(3))

	// df.groupby("city").mean(numeric_only=True)
	g := dataframe.Must(df.GroupBy("city"))
	fmt.Println(dataframe.Must(g.Mean()).ResetIndex(false))

	// df.query("rain > 700 and year == 2024")
	fmt.Println(dataframe.Must(df.Query("rain > 700 and year == 2024")))
}
Output:
    city  year   rain
0   Lyon  2023  830.5
1  Paris  2023  640.2
2   Nice  2024  760.1
    city    year    rain
0   Lyon  2023.5  820.25
1   Nice  2024.0  760.10
2  Paris  2023.5  619.45
   city  year   rain
2  Nice  2024  760.1
4  Lyon  2024  810.0

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	MaxRows    = 60
	MinRows    = 10
	MaxColumns = 20
)

Display limits, pandas' defaults: past MaxRows rows only the first and last MinRows/2 are shown; past MaxColumns columns only the first and last MaxColumns/2.

View Source
var (
	// ErrDType reports an operation the column's dtype does not support.
	ErrDType = errors.New("dataframe: unsupported dtype")
	// ErrColumn reports a column name that is not in the frame.
	ErrColumn = errors.New("dataframe: no such column")
	// ErrLabel reports an index label that is not in the index.
	ErrLabel = errors.New("dataframe: label not in index")
	// ErrLength reports data whose length does not match the frame or index.
	ErrLength = errors.New("dataframe: length mismatch")
	// ErrIndex reports a position out of range.
	ErrIndex = errors.New("dataframe: position out of range")
	// ErrArgument reports an invalid argument.
	ErrArgument = errors.New("dataframe: invalid argument")
	// ErrQuery reports a query expression that does not parse or evaluate.
	ErrQuery = errors.New("dataframe: bad query")
	// ErrParse reports input (CSV, dates, ...) that does not parse.
	ErrParse = errors.New("dataframe: parse error")
)

Errors returned by the package. They are wrapped with detail; test with errors.Is.

Functions

func Must

func Must[T any](v T, err error) T

Must returns v, and panics if err is not nil. It is meant for notebooks and examples, where an error should stop the cell:

df := dataframe.Must(dataframe.ReadCSVFile("data.csv"))

func Timestamp

func Timestamp(s string, layout ...string) (time.Time, error)

Timestamp parses one instant as ToDatetime parses a string.

Types

type AggSpec

type AggSpec struct {
	Column string
	Funcs  []string
}

AggSpec names the aggregations of one column, for GroupBy.Agg.

func Agg

func Agg(column string, funcs ...string) AggSpec

Agg returns an AggSpec: the column and the aggregations to apply to it ("sum", "mean", "std", "var", "min", "max", "median", "count", "size", "first", "last", "nunique", "prod").

type CSVOption

type CSVOption func(*csvConfig)

CSVOption configures ReadCSV. The options mirror the read_csv parameters of pandas that notebooks use; each one names the pandas parameter it stands for.

func CSVComment

func CSVComment(c byte) CSVOption

CSVComment sets a comment character: the rest of a line from it is ignored, and a line starting with it is skipped (pandas' comment).

func CSVDTypes

func CSVDTypes(dtypes map[string]DType) CSVOption

CSVDTypes sets the dtype of the named columns (pandas' dtype with a dict); a value that does not convert is an error. Names not in the file are ignored, as in pandas.

func CSVDateFormat

func CSVDateFormat(layout string) CSVOption

CSVDateFormat sets the layout of the CSVParseDates columns: a Go layout or a strftime pattern such as "%d/%m/%Y" (pandas' date_format). By default ISO 8601 and a list of common layouts are accepted.

func CSVFalseValues

func CSVFalseValues(tokens ...string) CSVOption

CSVFalseValues adds tokens read as false, besides False, FALSE and false (pandas' false_values).

func CSVHeader

func CSVHeader(present bool) CSVOption

CSVHeader says whether the first row (after the skipped rows) holds the column names. By default it does, unless CSVNames is given (pandas' header="infer"); CSVHeader(true) with CSVNames replaces the names the file has (header=0 with names), CSVHeader(false) reads every row as data (header=None), naming the columns "0", "1", ... when CSVNames is absent.

func CSVIndexCol

func CSVIndexCol(name string) CSVOption

CSVIndexCol makes the named column the index (pandas' index_col with a name).

func CSVIndexColumn

func CSVIndexColumn(i int) CSVOption

CSVIndexColumn makes the column at position i (among the columns read) the index (pandas' index_col with an integer). An unnamed column gives an unnamed index, so a file written by WriteCSV with its index reads back with CSVIndexColumn(0).

func CSVKeepDefaultNA

func CSVKeepDefaultNA(keep bool) CSVOption

CSVKeepDefaultNA says whether pandas' default missing-value tokens ("", "NA", "NaN", "null", "None", "#N/A", ...) count as missing, true by default (pandas' keep_default_na).

func CSVNAValues

func CSVNAValues(tokens ...string) CSVOption

CSVNAValues adds tokens read as missing values (pandas' na_values).

func CSVNRows

func CSVNRows(n int) CSVOption

CSVNRows reads at most n data rows (pandas' nrows).

func CSVNames

func CSVNames(names ...string) CSVOption

CSVNames sets the column names (pandas' names). A row with more fields than names gives its leading fields to the index, as in pandas.

func CSVParseDates

func CSVParseDates(names ...string) CSVOption

CSVParseDates reads the named columns as Datetime (pandas' parse_dates with a list of names). A column holding a value that is not a date stays a String column, as pandas leaves it.

func CSVQuote

func CSVQuote(c byte) CSVOption

CSVQuote sets the quote character, '"' by default (pandas' quotechar); 0 disables quoting (quoting=QUOTE_NONE).

func CSVSeparator

func CSVSeparator(c byte) CSVOption

CSVSeparator sets the field separator, ',' by default (pandas' sep).

func CSVSkipBlankLines

func CSVSkipBlankLines(skip bool) CSVOption

CSVSkipBlankLines says whether empty and whitespace-only lines are skipped, true by default; otherwise they are rows of missing values (pandas' skip_blank_lines).

func CSVSkipRows

func CSVSkipRows(n int) CSVOption

CSVSkipRows skips the first n lines of the file, blank ones included, before the header (pandas' skiprows with an integer).

func CSVTrueValues

func CSVTrueValues(tokens ...string) CSVOption

CSVTrueValues adds tokens read as true, besides True, TRUE and true (pandas' true_values).

func CSVUseCols

func CSVUseCols(names ...string) CSVOption

CSVUseCols keeps only the named columns, in file order (pandas' usecols).

type CSVWriteOption

type CSVWriteOption func(*csvWriteConfig)

CSVWriteOption configures WriteCSV, mirroring pandas' to_csv parameters.

func CSVWriteHeader

func CSVWriteHeader(write bool) CSVWriteOption

CSVWriteHeader says whether the column names are written, true by default (pandas' header).

func CSVWriteIndex

func CSVWriteIndex(write bool) CSVWriteOption

CSVWriteIndex says whether the index is written as the first columns, true by default (pandas' index).

func CSVWriteLineTerminator

func CSVWriteLineTerminator(s string) CSVWriteOption

CSVWriteLineTerminator sets the line end, "\n" by default (pandas' lineterminator, whose default is the platform's).

func CSVWriteNARep

func CSVWriteNARep(s string) CSVWriteOption

CSVWriteNARep sets what a missing value is written as, "" by default (pandas' na_rep).

func CSVWriteSeparator

func CSVWriteSeparator(c byte) CSVWriteOption

CSVWriteSeparator sets the field separator, ',' by default (pandas' sep).

type Column

type Column struct {
	Name string
	Data any
}

Column names one column of data for New.

func Col

func Col(name string, data any) Column

Col returns a Column for New. data is anything NewSeries accepts, or a *Series (whose index then must match the frame's).

type ConcatOptions

type ConcatOptions struct {
	// Axis 0 stacks frames vertically (rows after rows); 1 places them side
	// by side, aligned on the index.
	Axis int
	// IgnoreIndex gives the result a range index (axis 0).
	IgnoreIndex bool
	// Inner keeps only the columns (axis 0) or labels (axis 1) every frame
	// has, instead of their union.
	Inner bool
}

ConcatOptions tunes Concat.

type DType

type DType uint8

DType is the element type of a column. The first thirteen values are the go-ndarray dtypes, in go-ndarray's order, so a numeric column converts to and from an ndarray dtype by a plain conversion. The others are the column kinds an array cannot hold: text, instants, categories and periods.

const (
	Float64 DType = DType(ndarray.Float64)
	Bool    DType = DType(ndarray.Bool)
	Int8    DType = DType(ndarray.Int8)
	Int16   DType = DType(ndarray.Int16)
	Int32   DType = DType(ndarray.Int32)
	Int64   DType = DType(ndarray.Int64)
	Uint8   DType = DType(ndarray.Uint8)
	Uint16  DType = DType(ndarray.Uint16)
	Uint32  DType = DType(ndarray.Uint32)
	Uint64  DType = DType(ndarray.Uint64)
	Float32 DType = DType(ndarray.Float32)
	// Complex64 and Complex128 columns hold and show complex numbers; they
	// take part in arithmetic and sums but have no order.
	Complex64  DType = DType(ndarray.Complex64)
	Complex128 DType = DType(ndarray.Complex128)
	// String is a column of Go strings.
	String DType = 13
	// Datetime is a column of instants, stored as int64 nanoseconds since the
	// Unix epoch, UTC.
	Datetime DType = 14
	// Category is a column of int32 codes into a list of string categories.
	Category DType = 15
	// Period is a column of calendar periods (a month, a quarter, ...), stored
	// as int64 ordinals counted from the period holding the Unix epoch.
	Period DType = 16
)

The column dtypes.

func ParseDType

func ParseDType(name string) (DType, error)

ParseDType returns the dtype with the given name. Besides the names String returns it accepts "int" (int64), "float" (float64), "str" and "object" (string), and "datetime64[ns]" (datetime).

func (DType) IsNumeric

func (d DType) IsNumeric() bool

IsNumeric reports whether the dtype is a number type (integer, float or complex) or bool, i.e. a column that converts to an ndarray as is.

func (DType) String

func (d DType) String() string

String returns the dtype's name: "float64", "int64", "string", "datetime", "category", ...

type DataFrame

type DataFrame struct {
	// contains filtered or unexported fields
}

DataFrame is a table of named columns of equal length sharing one Index of row labels. Each column has its own dtype; numeric columns are go-ndarray arrays. A DataFrame is immutable: operations return new frames, sharing the columns they do not change.

func Concat

func Concat(frames ...*DataFrame) (*DataFrame, error)

Concat stacks frames vertically: the columns are the union of the frames' columns in order of appearance (a frame lacking one contributes missing values), and the indexes are concatenated (pandas' concat).

func ConcatWith

func ConcatWith(opts ConcatOptions, frames ...*DataFrame) (*DataFrame, error)

ConcatWith is Concat with options.

func FromArray

func FromArray(a *ndarray.Array, names ...string) (*DataFrame, error)

FromArray returns a frame of the columns of a two-dimensional array, named by names (or "0", "1", ... when names is empty).

func FromSeries

func FromSeries(series ...*Series) (*DataFrame, error)

FromSeries returns a frame of the series as columns, aligned on their indexes: when they differ, the rows are the union of the labels (in sorted order, as pandas builds a frame from a dict of series), and a series lacking a label gets a missing value there.

func Merge

func Merge(left, right *DataFrame, opts MergeOptions) (*DataFrame, error)

Merge joins two frames on key columns, as pandas' merge. Rows come in pandas' order: inner and left joins follow the left frame, a right join the right frame, an outer join the sorted keys. Missing keys match each other, as in pandas. The result has a range index.

Example
package main

import (
	"fmt"

	"github.com/go-dataframe/dataframe"
)

func main() {
	left := dataframe.Must(dataframe.New(
		dataframe.Col("id", []int{1, 2, 3}),
		dataframe.Col("name", []string{"ada", "bob", "cy"}),
	))
	right := dataframe.Must(dataframe.New(
		dataframe.Col("id", []int{3, 1, 1}),
		dataframe.Col("score", []float64{7.5, 9, 8}),
	))
	// pd.merge(left, right, on="id", how="left")
	fmt.Println(dataframe.Must(dataframe.Merge(left, right, dataframe.MergeOptions{On: []string{"id"}, How: "left"})))
}
Output:
   id name  score
0   1  ada    9.0
1   1  ada    8.0
2   2  bob    NaN
3   3   cy    7.5

func New

func New(cols ...Column) (*DataFrame, error)

New returns a frame of the given columns, in order, with a range index.

df, err := dataframe.New(
	dataframe.Col("city", []string{"Lyon", "Paris"}),
	dataframe.Col("pop", []int{522_000, 2_103_000}),
)

func ReadCSV

func ReadCSV(r io.Reader, opts ...CSVOption) (*DataFrame, error)

ReadCSV reads a CSV table, as pandas' read_csv does: the first row names the columns, each column's dtype is inferred from all its values (int64, uint64, float64, bool or string; see CSVParseDates and CSVDTypes for the others), pandas' default missing-value tokens are missing, and the index is a range unless CSVIndexCol says otherwise.

Fields follow RFC 4180: quoted fields may hold separators, doubled quotes and line breaks; lines end with LF, CRLF or CR; a UTF-8 byte order mark is skipped. A row with fewer fields than the header gets missing values; a row with more is an error naming its line, except the first data row, whose extra leading fields become the index (as in pandas).

An integer or bool column with missing values keeps its dtype, the missing rows marked in its validity, where pandas would make it float64 or object. String values share one buffer holding the input: a string kept keeps the whole input alive (see docs/design.md).

func ReadCSVFile

func ReadCSVFile(path string, opts ...CSVOption) (*DataFrame, error)

ReadCSVFile reads a CSV file as ReadCSV reads one.

func (*DataFrame) Add

func (df *DataFrame) Add(other any) (*DataFrame, error)

Add returns df + other, other a scalar or a frame (aligned on labels and column names).

func (*DataFrame) Apply

func (df *DataFrame) Apply(name string, f func(Row) any) (*Series, error)

Apply calls f on every row and returns a series of the results, indexed like the frame, with an inferred dtype (pandas' df.apply(f, axis=1)).

func (*DataFrame) ApplyColumns

func (df *DataFrame) ApplyColumns(f func(*Series) (*Series, error)) (*DataFrame, error)

ApplyColumns calls f on every column and returns the frame of the results, which must keep the frame's length.

func (*DataFrame) AsType

func (df *DataFrame) AsType(dtypes map[string]DType) (*DataFrame, error)

AsType returns the frame with the named columns converted, as Series.AsType converts.

func (*DataFrame) AsTypeAll

func (df *DataFrame) AsTypeAll(dt DType) (*DataFrame, error)

AsTypeAll returns the frame with every column converted to one dtype.

func (*DataFrame) At

func (df *DataFrame) At(label any, column string) (any, error)

At returns the value at a row label and column name (pandas' df.at).

func (*DataFrame) BFill

func (df *DataFrame) BFill() *DataFrame

BFill backward-fills every column, as Series.BFill.

func (*DataFrame) Column

func (df *DataFrame) Column(name string) (*Series, error)

Column returns one column as a series sharing the frame's index.

func (*DataFrame) ColumnAt

func (df *DataFrame) ColumnAt(i int) (*Series, error)

ColumnAt returns the column at position i.

func (*DataFrame) Columns

func (df *DataFrame) Columns() []string

Columns returns the column names, in order.

func (*DataFrame) Copy

func (df *DataFrame) Copy() *DataFrame

Copy returns a deep copy of the frame.

func (*DataFrame) Count

func (df *DataFrame) Count() *Series

Count returns the number of present values in every column.

func (*DataFrame) DTypes

func (df *DataFrame) DTypes() []DType

DTypes returns the dtype of each column, in column order.

func (*DataFrame) DTypesSeries

func (df *DataFrame) DTypesSeries() *Series

DTypesSeries returns the dtypes as a string series indexed by column name, the way pandas shows df.dtypes.

func (*DataFrame) Describe

func (df *DataFrame) Describe() *DataFrame

Describe returns summary statistics of the numeric columns, as pandas' describe(): count, mean, std, min, 25%, 50%, 75%, max. A frame without numeric columns is described as text: count, unique, top, freq.

func (*DataFrame) Display

func (df *DataFrame) Display() map[string][]byte

Display returns the frame for a notebook: text/plain as String, text/html as HTML.

func (*DataFrame) Div

func (df *DataFrame) Div(other any) (*DataFrame, error)

Div returns df / other.

func (*DataFrame) Drop

func (df *DataFrame) Drop(names ...string) (*DataFrame, error)

Drop returns the frame without the named columns.

func (*DataFrame) DropNA

func (df *DataFrame) DropNA(subset ...string) (*DataFrame, error)

DropNA returns the rows with no missing value in the subset columns (all columns when none are named): pandas' dropna().

func (*DataFrame) DropNAAll

func (df *DataFrame) DropNAAll(subset ...string) (*DataFrame, error)

DropNAAll returns the rows that have at least one value present in the subset columns: pandas' dropna(how="all").

func (*DataFrame) DropNAColumns

func (df *DataFrame) DropNAColumns() *DataFrame

DropNAColumns returns the frame without the columns that have a missing value: pandas' dropna(axis=1).

func (*DataFrame) DropNAThresh

func (df *DataFrame) DropNAThresh(thresh int, subset ...string) (*DataFrame, error)

DropNAThresh keeps the rows with at least thresh values present in the subset columns: pandas' dropna(thresh=thresh).

func (*DataFrame) Eval

func (df *DataFrame) Eval(expr string, vars ...map[string]any) (*Series, error)

Eval evaluates an expression of the Query language to a series, one value per row (pandas' eval).

func (*DataFrame) FFill

func (df *DataFrame) FFill() *DataFrame

FFill forward-fills every column, as Series.FFill.

func (*DataFrame) FillNA

func (df *DataFrame) FillNA(v any) *DataFrame

FillNA returns the frame with missing values replaced by v in every column whose dtype v converts to; the other columns are left as they are.

func (*DataFrame) FillNAColumns

func (df *DataFrame) FillNAColumns(values map[string]any) (*DataFrame, error)

FillNAColumns fills missing values column by column, from a map of column name to value.

func (*DataFrame) Filter

func (df *DataFrame) Filter(mask any) (*DataFrame, error)

Filter returns the rows where mask is true (pandas' df[mask]). The mask is a bool series (aligned by label) or a []bool.

func (*DataFrame) GroupBy

func (df *DataFrame) GroupBy(keys ...string) (*GroupBy, error)

GroupBy groups the frame's rows by the named key columns.

func (*DataFrame) HTML

func (df *DataFrame) HTML() string

HTML formats the frame as an HTML table, as pandas' notebook display.

func (*DataFrame) Head

func (df *DataFrame) Head(n int) *DataFrame

Head returns the first n rows (with a negative n, all but the last -n).

func (*DataFrame) IAt

func (df *DataFrame) IAt(i, j int) (any, error)

IAt returns the value at row position i and column position j (pandas' df.iat); negative positions count from the end.

func (*DataFrame) Iloc

func (df *DataFrame) Iloc(rows Selector, cols ...Selector) (*DataFrame, error)

Iloc selects rows by position, and optionally columns by position:

df.Iloc(dataframe.Slice(0, 5))                        // df.iloc[0:5]
df.Iloc(dataframe.Pos(0, 2), dataframe.Slice(1, 3))   // df.iloc[[0, 2], 1:3]
df.Iloc(dataframe.Mask(m))                            // df.iloc[m]

func (*DataFrame) Index

func (df *DataFrame) Index() *Index

Index returns the row labels.

func (*DataFrame) IsNA

func (df *DataFrame) IsNA() *DataFrame

IsNA returns a frame of bools, true where a value is missing.

func (*DataFrame) Join

func (df *DataFrame) Join(other *DataFrame, how, lsuffix, rsuffix string) (*DataFrame, error)

Join joins another frame on the index labels (pandas' join): how is "left" (the default when empty), "right", "inner" or "outer"; column names both frames have take the suffixes.

func (*DataFrame) Len

func (df *DataFrame) Len() int

Len returns the number of rows.

func (*DataFrame) Loc

func (df *DataFrame) Loc(rows Selector, cols ...string) (*DataFrame, error)

Loc selects rows by label (or mask), and optionally columns by name:

df.Loc(dataframe.Labels("a", "c"))                    // df.loc[["a", "c"]]
df.Loc(dataframe.LabelRange("2020-01", "2020-03"))    // df.loc["2020-01":"2020-03"]
df.Loc(dataframe.Mask(m), "x", "y")                   // df.loc[m, ["x", "y"]]

func (*DataFrame) Max

func (df *DataFrame) Max() *Series

Max returns the maximum of each numeric column.

func (*DataFrame) Mean

func (df *DataFrame) Mean() *Series

Mean returns the mean of each numeric column.

func (*DataFrame) Median

func (df *DataFrame) Median() *Series

Median returns the median of each numeric column.

func (*DataFrame) Melt

func (df *DataFrame) Melt(idVars, valueVars []string) (*DataFrame, error)

Melt reshapes wide data to long (pandas' melt): the id columns repeat, and each value column becomes rows of ("variable", "value") pairs. With no value columns named, every non-id column is one.

func (*DataFrame) Merge

func (df *DataFrame) Merge(right *DataFrame, opts MergeOptions) (*DataFrame, error)

Merge joins the frame with another, as the Merge function.

func (*DataFrame) Min

func (df *DataFrame) Min() *Series

Min returns the minimum of each numeric column.

func (*DataFrame) Mul

func (df *DataFrame) Mul(other any) (*DataFrame, error)

Mul returns df * other.

func (*DataFrame) NotNA

func (df *DataFrame) NotNA() *DataFrame

NotNA is the negation of IsNA.

func (*DataFrame) Pivot

func (df *DataFrame) Pivot(index, columns, values string) (*DataFrame, error)

Pivot reshapes long data to wide: rows from the index column, columns from the columns column, cells from the values column (pandas' pivot). A repeated (index, columns) pair is an error; use PivotTable to aggregate.

func (*DataFrame) PivotTable

func (df *DataFrame) PivotTable(index, columns, values, aggfunc string) (*DataFrame, error)

PivotTable is Pivot with repeated pairs aggregated by aggfunc ("mean", pandas' default, "sum", "count", ...).

func (*DataFrame) Query

func (df *DataFrame) Query(expr string, vars ...map[string]any) (*DataFrame, error)

Query returns the rows for which a boolean expression holds (pandas' query). The expression language is small and is parsed, never executed as code:

  • column names, bare (price) or in backquotes (`unit price`); "index" names the index when no column is called that;
  • @name, a variable from vars;
  • numbers, 'strings' or "strings", true/false (or True/False), lists [1, 2, 3];
  • arithmetic + - * / // % ** and unary minus;
  • comparisons == != < <= > >=, chained as in 1 < x < 5;
  • x in [...] and x not in [...];
  • and, or, not (also &, |, ~), and parentheses;
  • the functions isna(x), notna(x) and abs(x), and the methods x.isna() and x.notna().

Comparisons against a missing value are false (!= is true), as for NaN in pandas.

func (*DataFrame) Reindex

func (df *DataFrame) Reindex(labels any) (*DataFrame, error)

Reindex returns the frame with rows for the given labels (an *Index or anything NewIndex accepts), in that order; a label the frame lacks gives a row of missing values.

func (*DataFrame) ReindexColumns

func (df *DataFrame) ReindexColumns(names ...string) *DataFrame

ReindexColumns returns the frame with the given columns in that order; a name the frame lacks gives an all-missing float64 column.

func (*DataFrame) Rename

func (df *DataFrame) Rename(names map[string]string) *DataFrame

Rename returns the frame with columns renamed by the map; names it does not mention are kept, and an unknown key is ignored, as in pandas.

func (*DataFrame) Resample

func (df *DataFrame) Resample(rule string) (*Resampler, error)

Resample bins the rows of a frame with a datetime index by time (pandas' resample): fixed bins (e.g. "15min", "h", "D", "7D") start at midnight of the first day and are labelled by their start; calendar bins ("W", "ME", "QE", "YE", "MS", "QS", "YS") hold whole weeks, months, quarters or years. Every bin from the first to the last is in the result, empty ones included (their sum is 0, their mean missing).

Example
package main

import (
	"fmt"

	"github.com/go-dataframe/dataframe"
)

func main() {
	ts := dataframe.Must(dataframe.ToDatetime(dataframe.Must(dataframe.NewSeries("when",
		[]string{"2024-01-01 09:00", "2024-01-01 17:30", "2024-01-03 08:00"}))))
	df := dataframe.Must(dataframe.New(dataframe.Col("when", ts), dataframe.Col("kwh", []float64{1.5, 2, 4})))
	df = dataframe.Must(df.SetIndex("when"))
	// df.resample("D").sum()
	fmt.Println(dataframe.Must(dataframe.Must(df.Resample("D")).Sum()).ResetIndex(false))
}
Output:
        when  kwh
0 2024-01-01  3.5
1 2024-01-02  0.0
2 2024-01-03  4.0

func (*DataFrame) ResampleOn

func (df *DataFrame) ResampleOn(column, rule string) (*Resampler, error)

ResampleOn bins by a datetime column instead of the index.

func (*DataFrame) ResetIndex

func (df *DataFrame) ResetIndex(drop bool) *DataFrame

ResetIndex returns the frame with a range index. Unless drop is set, the old index levels become the first columns, named after the levels ("index" for an unnamed one-level index, "level_0", "level_1", ... for unnamed levels of a multi-level one).

func (*DataFrame) Round

func (df *DataFrame) Round(decimals int) *DataFrame

Round rounds every float column, as Series.Round.

func (*DataFrame) Select

func (df *DataFrame) Select(names ...string) (*DataFrame, error)

Select returns the frame restricted to the named columns, in that order.

func (*DataFrame) Series

func (df *DataFrame) Series() []*Series

Series returns every column as a series, in order.

func (*DataFrame) SetColumns

func (df *DataFrame) SetColumns(names ...string) (*DataFrame, error)

SetColumns returns the frame with all column names replaced.

func (*DataFrame) SetIndex

func (df *DataFrame) SetIndex(columns ...string) (*DataFrame, error)

SetIndex returns the frame indexed by the named columns (several make a multi-level index), which leave the columns, as pandas' set_index does by default.

func (*DataFrame) Shape

func (df *DataFrame) Shape() (rows, cols int)

Shape returns the number of rows and of columns.

func (*DataFrame) Shift

func (df *DataFrame) Shift(n int) *DataFrame

Shift shifts every column, as Series.Shift.

func (*DataFrame) SortIndex

func (df *DataFrame) SortIndex(ascending bool) *DataFrame

SortIndex returns the frame sorted by its index labels (every level, the first the most significant).

func (*DataFrame) SortValues

func (df *DataFrame) SortValues(by []string, ascending ...bool) (*DataFrame, error)

SortValues returns the frame sorted by the given columns, the first the most significant. ascending gives the direction: none means all ascending, one value applies to every key, otherwise one per key. The sort is stable and puts missing values last, like pandas' sort_values(kind="stable").

func (*DataFrame) Stack

func (df *DataFrame) Stack() (*Series, error)

Stack returns the frame as a series with one value per (row, column) pair, the column name becoming the last index level; missing values are dropped (pandas' stack).

func (*DataFrame) Std

func (df *DataFrame) Std() *Series

Std returns the sample standard deviation of each numeric column.

func (*DataFrame) String

func (df *DataFrame) String() string

String formats the frame as pandas prints it: every value cell gets a leading space (a negative number's sign takes its place), cells are right-aligned under right-aligned column names, columns are joined by one space, and the index is left-aligned.

func (*DataFrame) Sub

func (df *DataFrame) Sub(other any) (*DataFrame, error)

Sub returns df - other.

func (*DataFrame) Sum

func (df *DataFrame) Sum() *Series

Sum returns the sum of each numeric column.

func (*DataFrame) T

func (df *DataFrame) T() *DataFrame

T returns the transpose: one column per row, named after the row's label, and one row per column, labelled by its name. The values take the columns' common dtype, or become strings when they have none (pandas makes an object column there).

func (*DataFrame) Tail

func (df *DataFrame) Tail(n int) *DataFrame

Tail returns the last n rows (with a negative n, all but the first -n).

func (*DataFrame) ToPeriod

func (df *DataFrame) ToPeriod(freq string) (*DataFrame, error)

ToPeriod converts the frame's datetime index to periods (pandas' to_period).

func (*DataFrame) Unstack

func (df *DataFrame) Unstack() (*DataFrame, error)

Unstack pivots the last index level into columns. With one value column the new columns are named by the labels; with several, column_label.

func (*DataFrame) Values

func (df *DataFrame) Values() (*ndarray.Array, error)

Values returns the frame as a two-dimensional array, rows by columns. All columns must be numeric or bool; the dtype is the one NumPy would pick for them all (an int column with missing values counts as float64), and missing values are NaN.

func (*DataFrame) Var

func (df *DataFrame) Var() *Series

Var returns the sample variance of each numeric column.

func (*DataFrame) WithColumn

func (df *DataFrame) WithColumn(name string, data any) (*DataFrame, error)

WithColumn returns the frame with a column set: replaced in place if the name exists, appended otherwise. data is a *Series (aligned on the frame's index by label, as pandas assigns one), a slice or array of the frame's length, or a scalar repeated on every row.

func (*DataFrame) WithIndex

func (df *DataFrame) WithIndex(ix *Index) (*DataFrame, error)

WithIndex returns the frame with the given index, of the same length.

func (*DataFrame) WriteCSV

func (df *DataFrame) WriteCSV(w io.Writer, opts ...CSVWriteOption) error

WriteCSV writes the frame as CSV, as pandas' to_csv does by default: a header row, the index as the first column(s) (headed by its name, empty when unnamed), missing values as empty fields, floats as Python prints them ("1.0", "0.1", "1e-05", "1e+16"), bools as True and False, instants as dates when all are at midnight and otherwise with the fraction of a second the column needs, and quotes only around fields holding the separator, a quote or a line break (RFC 4180).

func (*DataFrame) WriteCSVFile

func (df *DataFrame) WriteCSVFile(path string, opts ...CSVWriteOption) error

WriteCSVFile writes the frame to a file as WriteCSV writes it.

type DatetimeFields

type DatetimeFields struct {
	// contains filtered or unexported fields
}

DatetimeFields reads parts of a datetime series, as pandas' .dt accessor.

func (DatetimeFields) Day

func (d DatetimeFields) Day() *Series

Day returns the day of the month.

func (DatetimeFields) DayOfWeek

func (d DatetimeFields) DayOfWeek() *Series

DayOfWeek returns the day of the week, Monday 0 to Sunday 6, as pandas.

func (DatetimeFields) DayOfYear

func (d DatetimeFields) DayOfYear() *Series

DayOfYear returns the day of the year, from 1.

func (DatetimeFields) Hour

func (d DatetimeFields) Hour() *Series

Hour returns the hour.

func (DatetimeFields) Minute

func (d DatetimeFields) Minute() *Series

Minute returns the minute.

func (DatetimeFields) Month

func (d DatetimeFields) Month() *Series

Month returns the month, 1 to 12.

func (DatetimeFields) Normalize

func (d DatetimeFields) Normalize() *Series

Normalize returns each instant at midnight of its day.

func (DatetimeFields) Second

func (d DatetimeFields) Second() *Series

Second returns the second.

func (DatetimeFields) Strftime

func (d DatetimeFields) Strftime(layout string) *Series

Strftime formats each instant with a Go layout or a strftime pattern.

func (DatetimeFields) Year

func (d DatetimeFields) Year() *Series

Year returns the year of each instant.

type GroupBy

type GroupBy struct {
	// contains filtered or unexported fields
}

GroupBy is a frame split into groups of rows by the values of key columns, ready to aggregate. Groups come out sorted by key, and rows whose key is missing are left out, as pandas' groupby does by default (sort=True, dropna=True). Grouping is hash based: one pass to code the keys, then one pass per aggregation.

func (*GroupBy) Agg

func (g *GroupBy) Agg(specs ...AggSpec) (*DataFrame, error)

Agg applies several aggregations. A column with one function keeps its name; with several, each result is named column_func (pandas makes a two-level column index there; this package keeps column names flat).

func (*GroupBy) Apply

func (g *GroupBy) Apply(f func(key any, group *DataFrame) (*DataFrame, error)) (*DataFrame, error)

Apply calls f on each group's rows and concatenates the frames it returns, in group order.

func (*GroupBy) Count

func (g *GroupBy) Count() (*DataFrame, error)

Count returns the number of present values of each column in each group.

func (*GroupBy) First

func (g *GroupBy) First() (*DataFrame, error)

First returns the first present value of each column in each group.

func (*GroupBy) Groups

func (g *GroupBy) Groups() ([]any, []*DataFrame)

Groups returns each group's key (a Go value, or a []any tuple for several keys) and its rows as a frame, in group order.

func (*GroupBy) Last

func (g *GroupBy) Last() (*DataFrame, error)

Last returns the last present value of each column in each group.

func (*GroupBy) Max

func (g *GroupBy) Max() (*DataFrame, error)

Max returns the per-group maximum of each column.

func (*GroupBy) Mean

func (g *GroupBy) Mean() (*DataFrame, error)

Mean returns the per-group mean of each numeric column.

func (*GroupBy) Median

func (g *GroupBy) Median() (*DataFrame, error)

Median returns the per-group median.

func (*GroupBy) Min

func (g *GroupBy) Min() (*DataFrame, error)

Min returns the per-group minimum of each column.

func (*GroupBy) NGroups

func (g *GroupBy) NGroups() int

NGroups returns the number of groups.

func (*GroupBy) NUnique

func (g *GroupBy) NUnique() (*DataFrame, error)

NUnique returns the number of distinct present values per group.

func (*GroupBy) Select

func (g *GroupBy) Select(columns ...string) (*GroupBy, error)

Select restricts the aggregated columns to the named ones (pandas' df.groupby(k)[cols]).

func (*GroupBy) Size

func (g *GroupBy) Size() *Series

Size returns the number of rows of each group, as a series named "size".

func (*GroupBy) Std

func (g *GroupBy) Std() (*DataFrame, error)

Std returns the per-group sample standard deviation.

func (*GroupBy) String

func (g *GroupBy) String() string

String describes the grouping.

func (*GroupBy) Sum

func (g *GroupBy) Sum() (*DataFrame, error)

Sum returns the per-group sum of each numeric column.

func (*GroupBy) Transform

func (g *GroupBy) Transform(column, fn string) (*Series, error)

Transform returns, for every row of the frame, its group's aggregate of the named column (pandas' groupby(k)[col].transform(fn)); rows whose key is missing get a missing value.

func (*GroupBy) Var

func (g *GroupBy) Var() (*DataFrame, error)

Var returns the per-group sample variance.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index holds the row labels of a Series or DataFrame. It is a range (0, 1, 2, ... as a frame gets by default; nothing is stored), one column of labels of any dtype (numbers, strings, instants: a datetime index), or several such columns, one per level, for a multi-level index such as a group-by over several keys produces. An Index is immutable.

func NewIndex

func NewIndex(name string, data any) (*Index, error)

NewIndex returns an index of the given labels: any data NewSeries accepts.

func NewRangeIndex

func NewRangeIndex(n int) *Index

NewRangeIndex returns the index 0, 1, ..., n-1.

func (*Index) DType

func (ix *Index) DType() DType

DType returns the dtype of the first level.

func (*Index) Display

func (ix *Index) Display() map[string][]byte

Display returns the index for a notebook, as text.

func (*Index) Get

func (ix *Index) Get(label any) ([]int, error)

Get returns the positions of a label (a []any tuple, or a prefix of one, for a multi-level index). A missing label is an ErrLabel.

func (*Index) IsRange

func (ix *Index) IsRange() bool

IsRange reports a default range index.

func (*Index) Label

func (ix *Index) Label(i int) any

Label returns the label at position i: a Go value for a one-level index (nil when missing), a []any tuple for a multi-level one.

func (*Index) Labels

func (ix *Index) Labels() []any

Labels returns every label, as Label does.

func (*Index) Len

func (ix *Index) Len() int

Len returns the number of labels.

func (*Index) Level

func (ix *Index) Level(k int) (*Series, error)

Level returns level k as a Series named after the level.

func (*Index) NLevels

func (ix *Index) NLevels() int

NLevels returns the number of levels: 1 unless the index is multi-level.

func (*Index) Name

func (ix *Index) Name() string

Name returns the name of the first level ("" when unnamed).

func (*Index) Names

func (ix *Index) Names() []string

Names returns the level names.

func (*Index) Rename

func (ix *Index) Rename(names ...string) (*Index, error)

Rename returns the index with new level names.

func (*Index) String

func (ix *Index) String() string

String formats the index the way pandas prints one.

func (*Index) Values

func (ix *Index) Values() (*ndarray.Array, error)

Values returns the labels of a one-level numeric (or datetime, as int64 nanoseconds) index as an array.

type MergeOptions

type MergeOptions struct {
	// How is "inner" (the default), "left", "right", "outer" or "cross".
	How string
	// On names key columns both frames have. When On, LeftOn and RightOn
	// are all empty, the keys are the columns the frames have in common.
	On []string
	// LeftOn and RightOn name key columns that differ between the frames,
	// pairwise.
	LeftOn, RightOn []string
	// Suffixes are appended to non-key columns both frames have; the
	// default is "_x" and "_y".
	Suffixes [2]string
	// Indicator adds a column "_merge" saying where each row came from:
	// "both", "left_only" or "right_only".
	Indicator bool
}

MergeOptions describes a database-style join of two frames.

type Resampler

type Resampler struct {
	// contains filtered or unexported fields
}

Resampler is a frame's rows binned by time, ready to aggregate.

func (*Resampler) Agg

func (r *Resampler) Agg(specs ...AggSpec) (*DataFrame, error)

Agg applies several aggregations, as GroupBy.Agg.

func (*Resampler) Count

func (r *Resampler) Count() (*DataFrame, error)

Count returns the number of present values per bin.

func (*Resampler) First

func (r *Resampler) First() (*DataFrame, error)

First returns the first present value per bin.

func (*Resampler) Last

func (r *Resampler) Last() (*DataFrame, error)

Last returns the last present value per bin.

func (*Resampler) Max

func (r *Resampler) Max() (*DataFrame, error)

Max returns the maximum per bin.

func (*Resampler) Mean

func (r *Resampler) Mean() (*DataFrame, error)

Mean returns the mean per bin.

func (*Resampler) Median

func (r *Resampler) Median() (*DataFrame, error)

Median returns the median per bin.

func (*Resampler) Min

func (r *Resampler) Min() (*DataFrame, error)

Min returns the minimum per bin.

func (*Resampler) Size

func (r *Resampler) Size() *Series

Size returns the number of rows per bin.

func (*Resampler) Std

func (r *Resampler) Std() (*DataFrame, error)

Std returns the sample standard deviation per bin.

func (*Resampler) Sum

func (r *Resampler) Sum() (*DataFrame, error)

Sum returns the sum of each numeric column per bin.

type Rolling

type Rolling struct {
	// contains filtered or unexported fields
}

Rolling is a moving window over a series, ready to aggregate.

func (*Rolling) Max

func (r *Rolling) Max() *Series

Max returns the moving maximum.

func (*Rolling) Mean

func (r *Rolling) Mean() *Series

Mean returns the moving mean.

func (*Rolling) Median

func (r *Rolling) Median() *Series

Median returns the moving median.

func (*Rolling) Min

func (r *Rolling) Min() *Series

Min returns the moving minimum.

func (*Rolling) Std

func (r *Rolling) Std() *Series

Std returns the moving sample standard deviation.

func (*Rolling) Sum

func (r *Rolling) Sum() *Series

Sum returns the moving sum.

type Row

type Row struct {
	// contains filtered or unexported fields
}

Row is one row of a frame, as Apply hands it to a function.

func (Row) Float

func (r Row) Float(column string) float64

Float returns the value in the named column as a float64 (NaN when it is missing or not a number).

func (Row) Get

func (r Row) Get(column string) any

Get returns the value in the named column (nil when missing or when there is no such column).

func (Row) Label

func (r Row) Label() any

Label returns the row's index label.

func (Row) Position

func (r Row) Position() int

Position returns the row's position.

type Selector

type Selector struct {
	// contains filtered or unexported fields
}

Selector picks rows (or, for Iloc, columns): all of them, a range or list of positions, a list or inclusive range of labels, or a boolean mask. Build one with All, Slice, Pos, Labels, LabelRange or Mask.

func All

func All() Selector

All selects everything (pandas' ":").

func LabelRange

func LabelRange(from, to any) Selector

LabelRange selects from label from to label to, both included, as pandas' loc[from:to]. A nil bound is open. A label that is absent is placed by binary search, which needs a sorted index.

func Labels

func Labels(l ...any) Selector

Labels selects the rows with the given labels, in that order (a []any tuple, or a prefix of one, for a multi-level index).

func Mask

func Mask(m any) Selector

Mask selects the rows where a mask is true: a []bool of the right length, or a bool *Series, which is aligned on the index by label when its index differs (it must then hold every label; missing values count as false).

func Pos

func Pos(i ...int) Selector

Pos selects the given positions, in that order; negative ones count from the end.

func Slice

func Slice(start, stop int) Selector

Slice selects positions [start, stop), as a Go slice expression would, except that negative values count from the end and out-of-range bounds are clipped, as in pandas' iloc[start:stop].

func SliceFrom

func SliceFrom(start int) Selector

SliceFrom selects positions from start to the end (iloc[start:]).

type Series

type Series struct {
	// contains filtered or unexported fields
}

Series is one named, labelled column: values of one dtype, with missing values marked in a validity bitmap, and an Index of row labels. A Series is immutable: every operation returns a new one, sharing storage where it can.

func ConcatSeries

func ConcatSeries(series ...*Series) (*Series, error)

ConcatSeries stacks series end to end.

func NewCategorical

func NewCategorical(name string, codes []int32, categories []string) (*Series, error)

NewCategorical returns a category series from codes into categories: code k stands for categories[k], and a negative code marks a missing value. A code past the last category is an error.

func NewSeries

func NewSeries(name string, data any) (*Series, error)

NewSeries returns a series over a copy of data, with a range index. data is a slice of any Go number type, []bool, []string, []time.Time, []any (nil is missing; the dtype is inferred), or a one-dimensional *ndarray.Array, which is shared rather than copied when it is contiguous.

func NewSeriesBitmap

func NewSeriesBitmap(name string, data any, validity []uint64) (*Series, error)

NewSeriesBitmap is NewSeries with a packed validity bitmap: bit i%64 of word i/64 set means value i is present; a clear bit marks it missing (its slot in data is kept but ignored). This is the Arrow validity bit order read as little-endian 64-bit words. A nil bitmap means every value is present; otherwise it must hold at least one bit per value, and the bits past the last value are ignored. The bitmap is copied.

func NewSeriesIndexed

func NewSeriesIndexed(name string, data any, index *Index) (*Series, error)

NewSeriesIndexed is NewSeries with the given row labels.

func NewSeriesMasked

func NewSeriesMasked(name string, data any, valid []bool) (*Series, error)

NewSeriesMasked is NewSeries with a validity mask: valid[i] false marks value i missing (its slot in data is kept but ignored). valid must be as long as data.

func ToDatetime

func ToDatetime(s *Series, layout ...string) (*Series, error)

ToDatetime converts a series to datetime. A string series is parsed (ISO 8601 and common layouts, or the given layout: a Go layout or a strftime pattern such as "%d/%m/%Y"); a string that does not parse is an error. An integer series is read as nanoseconds since the epoch; a datetime series is returned as is.

func (*Series) Abs

func (s *Series) Abs() (*Series, error)

Abs returns |s|.

func (*Series) Add

func (s *Series) Add(other any) (*Series, error)

Add returns s + other: other is a scalar or a series (aligned by label). Types promote as NumPy promotes them; strings concatenate.

func (*Series) Agg

func (s *Series) Agg(name string) (any, error)

Agg reduces the series by name: "sum", "mean", "std", "var", "min", "max", "count", "median", "prod", "nunique", "first", "last" or "size".

func (*Series) And

func (s *Series) And(o *Series) (*Series, error)

And returns s & o for bool series.

func (*Series) AsType

func (s *Series) AsType(dt DType) (*Series, error)

AsType returns the series converted to another dtype.

func (*Series) At

func (s *Series) At(i int) (any, error)

At returns the value at position i (negative counts from the end), nil when missing.

func (*Series) BFill

func (s *Series) BFill() *Series

BFill replaces each missing value by the next present one (pandas' bfill).

func (*Series) Between

func (s *Series) Between(lo, hi any) (*Series, error)

Between returns lo <= s <= hi.

func (*Series) Categorical

func (s *Series) Categorical() (codes []int32, categories []string, err error)

Categorical returns a category series' codes (-1 where a value is missing) and its categories. Any other dtype is an ErrDType.

func (*Series) Copy

func (s *Series) Copy() *Series

Copy returns a deep copy.

func (*Series) Count

func (s *Series) Count() int

Count returns the number of present values.

func (*Series) CumMax

func (s *Series) CumMax() (*Series, error)

CumMax returns the running maximum, as float64.

func (*Series) CumMin

func (s *Series) CumMin() (*Series, error)

CumMin returns the running minimum, as float64.

func (*Series) CumProd

func (s *Series) CumProd() (*Series, error)

CumProd returns the running product, as float64.

func (*Series) CumSum

func (s *Series) CumSum() (*Series, error)

CumSum returns the running sum, as float64.

func (*Series) DType

func (s *Series) DType() DType

DType returns the dtype of the values.

func (*Series) Diff

func (s *Series) Diff(n int) (*Series, error)

Diff returns s minus s shifted by n (pandas' diff), as float64.

func (*Series) Display

func (s *Series) Display() map[string][]byte

Display returns the series for a notebook.

func (*Series) Div

func (s *Series) Div(other any) (*Series, error)

Div returns s / other, true division (integers give float64).

func (*Series) DropNA

func (s *Series) DropNA() *Series

DropNA returns the present values.

func (*Series) Dt

func (s *Series) Dt() (DatetimeFields, error)

Dt returns the datetime accessor; it fails on a series of another dtype.

func (*Series) Eq

func (s *Series) Eq(other any) (*Series, error)

Eq returns s == other, elementwise; other is a scalar or a series.

func (*Series) FFill

func (s *Series) FFill() *Series

FFill returns the series with each missing value replaced by the last present one before it (pandas' ffill); leading missing values stay.

func (*Series) FillNA

func (s *Series) FillNA(v any) (*Series, error)

FillNA returns the series with missing values replaced by v, which must convert to the series' dtype (an int fills a float series; a float fills an int series only when it is integral).

func (*Series) Filter

func (s *Series) Filter(mask any) (*Series, error)

Filter returns the values where mask is true.

func (*Series) Floats

func (s *Series) Floats() ([]float64, error)

Floats returns the values as float64s, missing values as NaN. It accepts every real number dtype and bool.

func (*Series) FloorDiv

func (s *Series) FloorDiv(other any) (*Series, error)

FloorDiv returns s // other (Python's floor division).

func (*Series) Ge

func (s *Series) Ge(other any) (*Series, error)

Ge returns s >= other.

func (*Series) Get

func (s *Series) Get(label any) (any, error)

Get returns the value with row label label. A label held by several rows gives the first.

func (*Series) Gt

func (s *Series) Gt(other any) (*Series, error)

Gt returns s > other.

func (*Series) HTML

func (s *Series) HTML() string

HTML formats the series as a one-column HTML table.

func (*Series) Head

func (s *Series) Head(n int) *Series

Head returns the first n values (all of them if there are fewer; with a negative n, all but the last -n).

func (*Series) Iloc

func (s *Series) Iloc(sel Selector) (*Series, error)

Iloc selects values by position, as DataFrame.Iloc selects rows.

func (*Series) Index

func (s *Series) Index() *Index

Index returns the row labels.

func (*Series) IsIn

func (s *Series) IsIn(values ...any) (*Series, error)

IsIn returns whether each value is one of values (pandas' isin). A missing value is never in.

func (*Series) IsNA

func (s *Series) IsNA() *Series

IsNA returns a bool series, true where a value is missing (NaN counts as missing in a float series, as in pandas).

func (*Series) Items

func (s *Series) Items() []any

Items returns every value as a Go value, nil when missing.

func (*Series) Le

func (s *Series) Le(other any) (*Series, error)

Le returns s <= other.

func (*Series) Len

func (s *Series) Len() int

Len returns the number of values.

func (*Series) Loc

func (s *Series) Loc(sel Selector) (*Series, error)

Loc selects values by label or mask, as DataFrame.Loc selects rows.

func (*Series) Lt

func (s *Series) Lt(other any) (*Series, error)

Lt returns s < other.

func (*Series) Map

func (s *Series) Map(f func(any) any) (*Series, error)

Map applies f to every value (nil for a missing one) and builds a series of the results, whose dtype is inferred as for NewSeries([]any); a nil result is missing.

func (*Series) MapFloat

func (s *Series) MapFloat(f func(float64) float64) (*Series, error)

MapFloat applies f to every present value of a real series, giving a float64 series; missing values stay missing.

func (*Series) Max

func (s *Series) Max() any

Max returns the largest present value.

func (*Series) Mean

func (s *Series) Mean() float64

Mean returns the mean of the present values (NaN if there are none or the dtype is not real).

func (*Series) Median

func (s *Series) Median() float64

Median returns the median of the present values.

func (*Series) Min

func (s *Series) Min() any

Min returns the smallest present value (a Go value of the series' kind; time.Time for datetimes), nil when there is none.

func (*Series) Mod

func (s *Series) Mod(other any) (*Series, error)

Mod returns s % other, with the sign of the divisor, as in Python.

func (*Series) Mul

func (s *Series) Mul(other any) (*Series, error)

Mul returns s * other.

func (*Series) NUnique

func (s *Series) NUnique() int

NUnique returns the number of distinct present values.

func (*Series) Name

func (s *Series) Name() string

Name returns the series name.

func (*Series) Ne

func (s *Series) Ne(other any) (*Series, error)

Ne returns s != other.

func (*Series) Neg

func (s *Series) Neg() (*Series, error)

Neg returns -s.

func (*Series) Not

func (s *Series) Not() (*Series, error)

Not returns ~s for a bool series (missing gives true, as ~False).

func (*Series) NotNA

func (s *Series) NotNA() *Series

NotNA is the negation of IsNA.

func (*Series) Or

func (s *Series) Or(o *Series) (*Series, error)

Or returns s | o for bool series.

func (*Series) PctChange

func (s *Series) PctChange(n int) (*Series, error)

PctChange returns the relative change from n rows before (pandas' pct_change, without filling missing values).

func (*Series) Pow

func (s *Series) Pow(other any) (*Series, error)

Pow returns s ** other.

func (*Series) Prod

func (s *Series) Prod() float64

Prod returns the product of the present values.

func (*Series) Quantile

func (s *Series) Quantile(q float64) float64

Quantile returns the q-quantile, 0 <= q <= 1, interpolating linearly.

func (*Series) Reindex

func (s *Series) Reindex(labels any) (*Series, error)

Reindex returns the series with values for the given labels, as DataFrame.Reindex.

func (*Series) Rename

func (s *Series) Rename(name string) *Series

Rename returns the series under another name.

func (*Series) ResetIndex

func (s *Series) ResetIndex() *Series

ResetIndex returns the series with a range index.

func (*Series) Rolling

func (s *Series) Rolling(window int) (*Rolling, error)

Rolling returns a window of the given number of rows ending at each row; a row gets a value once the window holds window present values (pandas' default min_periods).

func (*Series) RollingMin

func (s *Series) RollingMin(window, minPeriods int) (*Rolling, error)

RollingMin is Rolling with min_periods: the least number of present values a window needs to give a value.

func (*Series) Round

func (s *Series) Round(decimals int) *Series

Round returns the series rounded to the given number of decimals (half to even, as NumPy rounds). Integer and non-numeric series are unchanged.

func (*Series) SetIndex

func (s *Series) SetIndex(ix *Index) (*Series, error)

SetIndex returns the series with other row labels of the same length.

func (*Series) Shift

func (s *Series) Shift(n int) *Series

Shift returns the series moved down by n rows (up for a negative n), the vacated rows missing (pandas' shift).

func (*Series) SortIndex

func (s *Series) SortIndex(ascending bool) *Series

SortIndex returns the series sorted by its index labels.

func (*Series) SortValues

func (s *Series) SortValues(ascending bool) *Series

SortValues returns the series sorted by value, stably, missing values last.

func (*Series) Std

func (s *Series) Std() float64

Std returns the sample standard deviation (ddof 1, as pandas).

func (*Series) String

func (s *Series) String() string

String formats the series as pandas prints it.

func (*Series) Strings

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

Strings returns every value formatted as text; missing values give "".

func (*Series) Sub

func (s *Series) Sub(other any) (*Series, error)

Sub returns s - other.

func (*Series) Sum

func (s *Series) Sum() float64

Sum returns the sum of the present values as a float64 (NaN for a dtype without a sum). SumValue keeps the exact type.

func (*Series) SumValue

func (s *Series) SumValue() any

SumValue returns the sum in the dtype pandas gives it: int64 for signed integers and bools, uint64 for unsigned ones, float64, or complex128; nil for a dtype without a sum.

func (*Series) Tail

func (s *Series) Tail(n int) *Series

Tail returns the last n values (with a negative n, all but the first -n).

func (*Series) ToFrame

func (s *Series) ToFrame() *DataFrame

ToFrame returns a one-column frame of the series.

func (*Series) ToPeriod

func (s *Series) ToPeriod(freq string) (*Series, error)

ToPeriod converts a datetime series to periods of a frequency: "Y", "Q", "M", "W", "D", "h", "min" or "s" (pandas' dt.to_period).

func (*Series) ToTimestamp

func (s *Series) ToTimestamp() (*Series, error)

ToTimestamp converts a period series to the instants its periods start.

func (*Series) Unique

func (s *Series) Unique() *Series

Unique returns the distinct present values in order of appearance.

func (*Series) Unstack

func (s *Series) Unstack() (*DataFrame, error)

Unstack pivots the last index level of a multi-level series into columns, one per distinct label (sorted), rows being the distinct remaining labels (sorted); a missing combination is a missing value (pandas' unstack).

func (*Series) Valid

func (s *Series) Valid() []bool

Valid returns, for each value, whether it is present (the negation of IsNA, as a plain slice).

func (*Series) ValidityBitmap

func (s *Series) ValidityBitmap() []uint64

ValidityBitmap returns a copy of the series' validity bitmap, in the layout NewSeriesBitmap takes, or nil when no value is masked. NaN in a float series is an in-band missing value, not a cleared bit: test floats for NaN as well.

func (*Series) ValueCounts

func (s *Series) ValueCounts() *Series

ValueCounts returns how often each distinct value occurs, most frequent first (ties in order of first appearance), indexed by the values and named "count", as pandas' value_counts.

func (*Series) Values

func (s *Series) Values() (*ndarray.Array, error)

Values returns the values as a go-ndarray array of the series' dtype; a datetime or period series gives its int64 storage. A series that owns its storage hands it out without copying. Missing values are left as they are stored (NaN for floats, zero otherwise); IsNA tells them apart. A string or category series has no array form.

func (*Series) Var

func (s *Series) Var() float64

Var returns the sample variance (ddof 1, as pandas).

func (*Series) VarDDOF

func (s *Series) VarDDOF(ddof int) float64

VarDDOF returns the variance with the given delta degrees of freedom.

func (*Series) Xor

func (s *Series) Xor(o *Series) (*Series, error)

Xor returns s ^ o for bool series.

Directories

Path Synopsis
Package arrowio reads and writes frames as Apache Arrow data: the Arrow IPC file format (Feather v2) and the Arrow IPC streaming format, and converts frames to and from Arrow record batches and tables; package parquetio builds Parquet on these conversions.
Package arrowio reads and writes frames as Apache Arrow data: the Arrow IPC file format (Feather v2) and the Arrow IPC streaming format, and converts frames to and from Arrow record batches and tables; package parquetio builds Parquet on these conversions.
Package dfplot draws DataFrames and Series, in the manner of the plot helpers of pandas (df.plot.line, df.plot.bar, ...) that notebooks lean on.
Package dfplot draws DataFrames and Series, in the manner of the plot helpers of pandas (df.plot.line, df.plot.bar, ...) that notebooks lean on.
Package parquetio reads and writes frames as Parquet files, through github.com/apache/arrow-go's pure-Go Parquet implementation (no cgo).
Package parquetio reads and writes frames as Parquet files, through github.com/apache/arrow-go's pure-Go Parquet implementation (no cgo).

Jump to

Keyboard shortcuts

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