Documentation ¶
Overview ¶
Package godata implements a Frame object for analyzing structured data in memory. The package is currently unstable and not ready for adoption.
Example (Joined) ¶
f1 := NewFrame(row.NewColumnIndexer("index")) f2 := NewFrame(row.NewColumnIndexer("index")) // f1 and f2 share an index, so the values will be joined together. f1.Put(row.Of("index", 0, "value", "foo")) f2.Put(row.Of("index", 0, "value", "bar")) // f1 and f2 have values at different indices, so index 1 will only contain a // value from f1, and index 2 will only contain a value from f2. f1.Put(row.Of("index", 1, "value", "something")) f2.Put(row.Of("index", 2, "value", "else")) joined, err := f1.Joined(f2) if err != nil { log.Fatalf("Joined: %v", err) } common, err := joined.Get(row.Of("index", 0)) if err != nil { log.Fatalf("Get: %v", err) } fmt.Println("index:", common["index"], "value:", common["value"]) leftOnly, err := joined.Get(row.Of("index", 1)) if err != nil { log.Fatalf("Get: %v", err) } fmt.Println("index:", leftOnly["index"], "value:", leftOnly["value"]) rightOnly, err := joined.Get(row.Of("index", 2)) if err != nil { log.Fatalf("Get: %v", err) } fmt.Println("index:", rightOnly["index"], "value:", rightOnly["value"])
Output: index: JoinResult{Left: 0, Right: 0} value: JoinResult{Left: foo, Right: bar} index: JoinResult{Left: 1} value: JoinResult{Left: something} index: JoinResult{Right: 2} value: JoinResult{Right: else}
Example (PutAndGet) ¶
frame := NewFrame(row.NewColumnIndexer("index1", "index2")) frame.Put(row.Of("index1", 123, "index2", "foo", "data1", "hello", "data2", "world")) frame.Put(row.Of("index1", 456, "index2", "bar", "data3", "something")) row, err := frame.Get(row.Of("index1", 123, "index2", "foo")) if err != nil { log.Fatalf("Get: %v", err) } fmt.Print(row["data1"])
Output: hello
Index ¶
- func GreaterOrEqual(val row.Data) rangeArg
- func LessThan(val row.Data) rangeArg
- type Frame
- func (f *Frame) Get(key row.Data) (row.Data, error)
- func (f *Frame) GetRange(args ...rangeArg) ([]row.Data, error)
- func (f *Frame) GroupBy(indexer row.Indexer) (*Frame, error)
- func (f *Frame) Joined(frame *Frame) (*Frame, error)
- func (f *Frame) Pop(key row.Data) (row.Data, error)
- func (f *Frame) PopRange(args ...rangeArg) ([]row.Data, error)
- func (f *Frame) Put(data row.Data) (row.Data, error)
- func (f *Frame) String() string
- func (f *Frame) WithIndexer(indexer row.Indexer) (*Frame, error)
- type JoinResult
- type JoinResultIndexer
- type RowAction
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GreaterOrEqual ¶
GreaterOrEqual returns a range option that filters on rows greater than or equal to the given value.
Types ¶
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame represents multiple rows and multiple columns of data.
func (*Frame) Get ¶
Get returns the data for the given key. Returns error if the given key is invalid. Returns nil if there is no data for the given key.
func (*Frame) GetRange ¶
GetRange returns a list of all values in the given range. See GreaterOrEqual and LessThan. If no range is given, then this function returns all rows. If only a begin range is given, then this function returns all rows beginning with the given value. If only an end range is given, then this function returns all rows up to the given value.
func (*Frame) GroupBy ¶
GroupBy returns a new Frame object containing rows grouped by the given indexer. Each index corresponds to a row containing a single column group.Column, which is a slice of rows with that index.
func (*Frame) Joined ¶
Joined returns a new Frame object that contains the joined contents of the two frames. The indices of the frames must be compatible. The resulting Frame contains one row for each key in the union of keys for the left and right frames. The Data contains a JoinResult for each column of data, where Left is populated with the left side contents, and Right is populated with the right side contents. Left and Right are nil if they don't exist in the left and right sides.
func (*Frame) Pop ¶
Pop returns the data for the given key and deletes it from the Frame. Returns error if the given key is invalid. Returns nil if there is no data for the given key.
func (*Frame) PopRange ¶
PopRange returns a list of all values in the given range and deletes them from the Frame. See GetRange for details on the arguments.
func (*Frame) Put ¶
Put inserts the data into the frame, replacing and returning the existing data if an entry already exists. Returns error if the data cannot be indexed.
func (*Frame) String ¶
String returns the string representation of the Frame.
TODO: The output is ugly and potentially very long. Refactor the forRange to take a limit, and then print out a partial representation of the Frame if there are too many rows.
func (*Frame) WithIndexer ¶
WithIndexer returns a new Frame object with the same underlying data indexed by a new indexer. Returns error if the data cannot be indexed by the new indexer. Note that mutating rows in the returned Frame will also mutate the rows in the existing Frame. However, adding to or deleting rows from the returned Frame will not add to and delete from the existing Frame. WithIndexer assumes that the given Indexer gives each existing row a unique Index. If rows share an index, then one of the rows will be dropped. The dropped row is not defined by the API, and is subject to change.
type JoinResult ¶
type JoinResult struct { // Left contains the contents in the left side of the join, or nil if the // left frame did not contain a row for the key. Left must contain the same // index as Right. Left interface{} // Right contains the contents in the right side of the join, or nil if the // right frame did not contain a row for the key. Left must contain the same // index as Right. Right interface{} }
JoinResult represents the result of a join operation.
func (JoinResult) String ¶
func (j JoinResult) String() string
String returns the string representation of this JoinResult.
type JoinResultIndexer ¶
type JoinResultIndexer struct { // RowIndexer is the indexer to use for the RowData in either Left or Right. RowIndexer row.Indexer }
JoinResultIndexer indexes a JoinResult by delegating to the given RowIndexer.
Directories ¶
Path | Synopsis |
---|---|
Package group defines utilities for aggregating and slicing Frames.
|
Package group defines utilities for aggregating and slicing Frames. |
Package row defines row primitives that are used to construct a Frame.
|
Package row defines row primitives that are used to construct a Frame. |