Table

Table is a list of dicts, where each dict represents a row, with keys corresponding to column names and values to the respective entries in the table
Imports
open Array;
Table of Contents

Types

Table

(type)
type Table

Row

(type)
type Row

Functions

from_csv

Reads a CSV file and returns a Table.
def from_csv (path: String) : Table

to_csv

Writes a Table to a CSV file.
def to_csv (table: Table) (path: String) : Unit

columns

Returns the list of column names in the table.
def columns (table: Table) : Array String

select

Selects a subset of columns from the table.
def select (table: Table) (columns: Array String) : Table

filter

Filters rows in the table using a predicate function.
def filter (table: Table) (predicate: (row : Row) -> Bool) : Table

map_column

Applies a function to a column in all rows.
def map_column (table: Table) (column: String) (f: (a : t) -> b) : Table

summary

Applies a summary function to a column in the table.
def summary (table: Table) (column: String) (f: (a : Array Int) -> b) : b

group_by

Groups the table by a column, returning a list of tables (one per group). - For each unique value in the specified column, creates a group (table) of all rows with that value.
def group_by (table: Table) (column: String) : Array Table

pivot

Pivots a table: turns unique values from one column into new columns. - For each unique value in the `index` column of the input table, create a row in the output table. - For each unique value in the `columns` column, create a new column in the output table. - For each original row, place its value from the `values` column at the intersection defined by its `index` and `columns` values.
def pivot (table: Table) (index: String) (columns: String) (values: String) : Table

melt

Melts a table: turns columns into rows (unpivot). - For each row in the input table, and for each column in value_vars, creates a new row. - The new row contains all id_vars, the name of the melted column, and its value.
def melt (table: Table) (id_vars: Array String) (value_vars: Array String) (var_name: String) (value_name: String) : Table

nrow

Number of rows in the table.
def nrow (table: Table) : Int

ncol

Number of columns in the table.
def ncol (table: Table) : Int

cell

The integer cell at row `r` (0-based) of column `col` -- DACE's spatial cell reference.
def cell (table: Table) (r: Int) (col: String) : Int

mutate

Add a new column `newcol` whose value in each row is `f` applied to that row. This is the workhorse of data completion: filling a column with a formula over the other columns (e.g. `mutate t "total" (\row -> ...)`).
def mutate (table: Table) (newcol: String) (f: (row : Row) -> Int) : Table

sum_col

Sum of the integer column `column`.
def sum_col (table: Table) (column: String) : Int

mean_col

Integer mean (floor) of the column `column`.
def mean_col (table: Table) (column: String) : Int

max_col

Maximum of the integer column `column`.
def max_col (table: Table) (column: String) : Int

min_col

Minimum of the integer column `column`.
def min_col (table: Table) (column: String) : Int

count

Number of rows (COUNT).
def count (table: Table) : Int

arrange

Sort the rows in ascending order of `column` (arrange).
def arrange (table: Table) (column: String) : Table

head

The first `n` rows (head / take).
def head (table: Table) (n: Int) : Table

cumsum

Add a column `newcol` holding the running sum of `column` down the rows -- the cumulative-total completion pattern (e.g. a balance column).
def cumsum (table: Table) (column: String) (newcol: String) : Table

join

Inner-join `left` and `right` on equal values of key column `on`.
def join (left: Table) (right: Table) (on: String) : Table

spread

`spread` is `pivot`: long -> wide.
def spread (table: Table) (index: String) (columns: String) (values: String) : Table

gather

`gather` is `melt`: wide -> long.
def gather (table: Table) (id_vars: Array String) (value_vars: Array String) (var_name: String) (value_name: String) : Table