DataFrame

DataFrame

A DataFrame is a collection of equilength vector-like objects as "columns". The number of rows in the DataFrame is equal to the length of the columns, where the i-th row consists of the i-th element from each column.

This class supports optional row names, which are either null or an array of strings of length equal to the number of rows.

This class supports empty instances with a non-zero number of rows, which may be useful for piece-wise construction.

The vector-like object for each column is expected to have methods for the following generics:

The DataFrame itself defines methods for the following generics:

Constructor

new DataFrame(columns, optionsopt)

Source:
Parameters:
Name Type Attributes Default Description
columns Object | Map

Object or Map where keys are the column names and the values are equilength vector-like objects.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
numberOfRows number <optional>
<nullable>
null

Non-negative value specifying the number of rows in the DataFrame. If null, this is automatically determined from the length of the vectors in columns, or from the length of rowNames. If non-null, this should not conflict with the inferred lengths from columns or rowNames.

rowNames Array <optional>
<nullable>
null

Array of strings containing the names for each row. If non-null, this should have the same length as the vectors inside columns, if any exist. If null, no row names are used.

columnOrder Array <optional>
<nullable>
null

Array of strings specifying the ordering of the columns. If non-null, this should have the same values as the keys of columns. If null, an arbitrary ordering is obtained from columns.

metadata Object <optional>
{}

Object containing arbitrary metadata as key-value pairs.

Extends

Classes

DataFrame

Methods

$removeColumn(i) → {DataFrame}

Source:
Parameters:
Name Type Description
i string | number

Column to remove, either by name or index.

Returns:

A reference to this DataFrame after removing the specified column.

Type
DataFrame

$setColumn(i, value) → {DataFrame}

Source:
Parameters:
Name Type Description
i string | number

Identity of the column to add, either by name or index.

  • If i is a number, the column at the specified index is replaced. i should be non-negative and less than the number of columns.
  • If i is a string, any column with the same name is replaced. If no such column exists, a new column is appended to the DataFrame.
value *

Array-like column to set/add as the column.

Returns:

A reference to this DataFrame after adding/replacing the specified column.

Type
DataFrame

$setColumnNames(names) → {DataFrame}

Source:
Parameters:
Name Type Description
names Array

Array of unique strings containing the new name for each column. This should have the same length as DataFrame.columnNames.

Returns:

A reference to this DataFrame with modified column names.

Type
DataFrame

$setMetadata(value) → {Annotated}

Source:
Overrides:
Parameters:
Name Type Description
value Object

Object containing the metadata.

Returns:

A reference to this Annotated object.

Type
Annotated

$setRowNames(namesnullable) → {DataFrame}

Source:
Parameters:
Name Type Attributes Description
names Array <nullable>

Array of unique strings containing the new name for each row. This should have the same length as DataFrame.numberOfRows.

Alternatively, this may be null to remove any existing column names.

Returns:

A reference to this DataFrame with modified row names.

Type
DataFrame

$sliceColumns(i, optionsopt) → {DataFrame}

Source:
Parameters:
Name Type Attributes Default Description
i Array

Array of strings or indices specifying the columns to retain in the slice. This should refer to unique column names.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
inPlace boolean <optional>
false

Whether to mutate this DataFrame instance in place. If false, a new instance is returned.

Returns:

Reference to this DataFrame after slicing to the specified columns. If inPlace = true, this is a reference to the current instance, otherwise a new instance is created and returned.

Type
DataFrame

column(i) → {*}

Source:
Parameters:
Name Type Description
i string | number

Column to retrieve, either by name or index.

Returns:

The contents of column i as a vector-like object.

Type
*

columnNames() → {Array}

Source:
Returns:

Array of strings containing the column names in the specified order.

Type
Array

hasColumn(name) → {boolean}

Source:
Parameters:
Name Type Description
name string

Name of a column.

Returns:

Whether the column exists in this DataFrame.

Type
boolean

metadata() → {Map}

Source:
Overrides:
Returns:

Map containing arbitrary metadata.

Type
Map

numberOfColumns() → {number}

Source:
Returns:

Number of columns in this DataFrame.

Type
number

numberOfRows() → {number}

Source:
Returns:

Number of rows in this DataFrame.

Type
number

removeColumn(i, optionsopt) → {DataFrame}

Source:
Parameters:
Name Type Attributes Default Description
i string | number

Column to remove, either by name or index.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
inPlace boolean <optional>
false

Whether to mutate this DataFrame instance in place. If false, a new instance is returned.

Returns:

The DataFrame after removing the specified column. If inPlace = true, this is a reference to the current instance, otherwise a new instance is created and returned.

Type
DataFrame

rowNames() → (nullable) {Array}

Source:
Returns:

Array of strings containing row names, or null if no row names are available.

Type
Array

setColumn(i, value, optionsopt) → {DataFrame}

Source:
Parameters:
Name Type Attributes Default Description
i string | number

Identity of the column to add, either by name or index.

  • If i is a number, the column at the specified index is replaced. i should be non-negative and less than the number of columns.
  • If i is a string, any column with the same name is replaced. If no such column exists, a new column is appended to the DataFrame.
value *

Array-like column to set/add as the column.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
inPlace boolean <optional>
false

Whether to mutate this DataFrame instance in place. If false, a new instance is returned.

Returns:

The DataFrame after adding/replacing the specified column. If inPlace = true, this is a reference to the current instance, otherwise a new instance is created and returned.

Type
DataFrame

setColumnNames(names, optionsopt) → {DataFrame}

Source:
Parameters:
Name Type Attributes Default Description
names Array

Array of unique strings containing the new name for each column. This should have the same length as DataFrame.columnNames.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
inPlace boolean <optional>
false

Whether to mutate this DataFrame instance in place. If false, a new instance is returned.

Returns:

The DataFrame with modified column names. If inPlace = true, this is a reference to the current instance, otherwise a new instance is created and returned.

Type
DataFrame

setMetadata(value, optionsopt) → {Annotated}

Source:
Overrides:
Parameters:
Name Type Attributes Default Description
value Object | Map

Object containing the metadata.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
inPlace boolean <optional>
false

Whether to mutate this Annotated instance in place. If false, a new instance is returned.

Returns:

The Annotated object after replacing the metadata. If inPlace = true, this is a reference to the current instance, otherwise a new instance is created and returned.

Type
Annotated

setRowNames(namesnullable, optionsopt) → {DataFrame}

Source:
Parameters:
Name Type Attributes Default Description
names Array <nullable>

Array of unique strings containing the new name for each row. This should have the same length as DataFrame.numberOfRows.

Alternatively, this may be null to remove any existing column names.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
inPlace boolean <optional>
false

Whether to mutate this DataFrame instance in place. If false, a new instance is returned.

Returns:

The DataFrame with modified row names. If inPlace = true, this is a reference to the current instance, otherwise a new instance is created and returned.

Type
DataFrame

sliceColumns(i, optionsopt) → {DataFrame}

Source:
Parameters:
Name Type Attributes Default Description
i Array

Array of strings or indices specifying the columns to retain in the slice. This should refer to unique column names.

options Object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
inPlace boolean <optional>
false

Whether to mutate this DataFrame instance in place. If false, a new instance is returned.

Returns:

Reference to this DataFrame after slicing to the specified columns. If inPlace = true, this is a reference to the current instance, otherwise a new instance is created and returned.

Type
DataFrame