DataFrame
DataFrame is a high-performance, easy to use tabular structure with strongly-typed columns of different types.
In the API, the terms "Table" and "DataFrame" are used interchangeably.
Usage samples: https://public.datagrok.ai/js/samples/data-frame/manipulate Usage details: https://datagrok.ai/help/develop/advanced/data-frame Implementation details: https://datagrok.ai/help/develop/admin/architecture#in-memory-database
Constructors
new DataFrame()
new DataFrame(
dart
):DataFrame
Parameters
Parameter | Type |
---|---|
dart | any |
Returns
Source
Properties
Property | Modifier | Type |
---|---|---|
_dialogs | private | undefined | DataFrameDialogHelper |
_meta | public | undefined | DataFrameMetaHelper |
_plot | private | undefined | DataFramePlotHelper |
columns | public | ColumnList |
dart | readonly | any |
filter | public | BitSet |
rows | public | RowList |
tags | public | any |
temp | public | any |
Accessors
currentCell
get
currentCell():Cell
Current cell. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
set
currentCell(cell
):void
Current cell. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Parameters
Parameter | Type |
---|---|
cell | Cell |
Returns
Source
currentCol
get
currentCol():Column
<any
,any
>
Current column. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
set
currentCol(col
):void
Current column. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Parameters
Parameter | Type |
---|---|
col | Column <any , any > |
Returns
Column
<any
, any
>
Source
currentRow
get
currentRow():Row
Current row. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
set
currentRow(row
):void
Parameters
Parameter | Type |
---|---|
row | Row |
Returns
Source
currentRowIdx
get
currentRowIdx():number
Index of the current row.
set
currentRowIdx(idx
):void
Parameters
Parameter | Type |
---|---|
idx | number |
Returns
number
Source
dialogs
get
dialogs():DataFrameDialogHelper
Returns
Source
id
get
id():string
Id of the dataframe.
set
id(id
):void
Parameters
Parameter | Type |
---|---|
id | string |
Returns
string
Source
meta
get
meta():DataFrameMetaHelper
A helper to conveniently access certain metadata properties stored in tags
Returns
Source
mouseOverRowIdx
get
mouseOverRowIdx():number
Index of the mouse-over row.
set
mouseOverRowIdx(idx
):void
Parameters
Parameter | Type |
---|---|
idx | number |
Returns
number
Source
name
get
name():string
Name of the dataframe.
set
name(s
):void
Parameters
Parameter | Type |
---|---|
s | string |
Returns
string
Source
onColumnNameChanged
get
onColumnNameChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onColumnSelectionChanged
get
onColumnSelectionChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onColumnsAdded
get
onColumnsAdded():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onColumnsChanged
get
onColumnsChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onColumnsRemoved
get
onColumnsRemoved():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onCurrentCellChanged
get
onCurrentCellChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Returns
Observable
<any
>
Source
onCurrentColChanged
get
onCurrentColChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Returns
Observable
<any
>
Source
onCurrentRowChanged
get
onCurrentRowChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Returns
Observable
<any
>
Source
onDataChanged
get
onDataChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onFilterChanged
get
onFilterChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onMetadataChanged
get
onMetadataChanged():Observable
<EventData
<MapChangeArgs
<string
,string
>>>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<EventData
<MapChangeArgs
<string
, string
>>>
Source
onMouseOverColChanged
get
onMouseOverColChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onMouseOverRowChanged
get
onMouseOverRowChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onMouseOverRowGroupChanged
get
onMouseOverRowGroupChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onNameChanged
get
onNameChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onRowsAdded
get
onRowsAdded():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onRowsFiltered
get
onRowsFiltered():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onRowsFiltering
get
onRowsFiltering():Observable
<any
>
Returns
Observable
<any
>
Source
onRowsRemoved
get
onRowsRemoved():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onSelectionChanged
get
onSelectionChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
onSemanticTypeDetected
get
onSemanticTypeDetected():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/advanced/semantic-type-detection
Returns
Observable
<any
>
Source
onSemanticTypeDetecting
get
onSemanticTypeDetecting():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/advanced/semantic-type-detection
Returns
Observable
<any
>
Source
onValuesChanged
get
onValuesChanged():Observable
<any
>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable
<any
>
Source
plot
get
plot():DataFramePlotHelper
A helper for creating plots for this dataframe
Returns
Source
rowCount
get
rowCount():number
Returns number of rows in the table.
Returns
number
Source
selection
get
selection():BitSet
Returns a BitSet with selected rows.
Returns
Source
Methods
_event()
_event(
event
):Observable
<any
>
Parameters
Parameter | Type |
---|---|
event | string |
Returns
Observable
<any
>
Source
_exportReopen()
_exportReopen():
DataFrame
Returns
Source
append()
append(
t2
,inPlace
,columnsToAppend
):DataFrame
Appends two tables ('union' in SQL).
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
t2 | DataFrame | undefined | |
inPlace | boolean | false | whether to create a new table, or modify 'this' one. |
columnsToAppend | null | string [] | null |
Returns
Source
appendMerge()
appendMerge(
t
):void
Parameters
Parameter | Type |
---|---|
t | DataFrame |
Returns
void
Source
cell()
cell(
idx
,name
):Cell
Returns a Cell with the specified row and column.
Parameters
Parameter | Type | Description |
---|---|---|
idx | number | Row index. |
name | string | Column name. |
Returns
Source
changeColumnType()
changeColumnType(
column
,newType
,format
):Column
<any
,any
>
Converts a column with the specified name to [newType], removes the original column from its dataframe and adds the new column to it.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
column | string | Column <any , any > | undefined | |
newType | "string" | "bigint" | "object" | "int" | "double" | "bool" | "byte_array" | "datetime" | "qnum" | "dataframe" | undefined | |
format | null | string | null |
Returns
Column
<any
, any
>
Source
clone()
clone(
rowMask
,columnIds
,saveSelection
):DataFrame
Creates a new dataframe from the specified row mask and a list of columns.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
rowMask | null | BitSet | null | Rows to include. |
columnIds | null | string [] | null | Columns to include. |
saveSelection | boolean | false | Whether selection should be saved. |
Returns
Source
col()
col(
nameOrIndex
):null
|Column
<any
,any
>
Returns a Column with the specified name.
Parameters
Parameter | Type | Description |
---|---|---|
nameOrIndex | string | number | Column name. |
Returns
null
| Column
<any
, any
>
Source
fireValuesChanged()
fireValuesChanged():
void
Returns
void
Source
get()
get(
name
,idx
):any
Returns idx-th value of the specified columns.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | Column name. |
idx | number | Row index. |
Returns
any
Source
getCol()
getCol(
name
):Column
<any
,any
>
Same as col, but throws Error if column is not found
Parameters
Parameter | Type | Description |
---|---|---|
name | string | Column name. |
Returns
Column
<any
, any
>
Source
getDensity()
getDensity(
xBins
,yBins
,xColName
,yColName
):Int32Array
Parameters
Parameter | Type |
---|---|
xBins | number |
yBins | number |
xColName | string |
yColName | string |
Returns
Int32Array
Source
getSortedOrder()
getSortedOrder(
sortByColumnIds
,sortOrders
,rowMask
):Int32Array
Returns [Int32Array] that contains sorted order, or null for unsorted (original) order. See also Column.getSortedOrder. Sample: https://public.datagrok.ai/js/samples/data-frame/sorting/sorted-order
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
sortByColumnIds | ColumnId [] | undefined | Collection of [Column]s to use as keys for sorting. |
sortOrders | null | boolean [] | null | List of sort orders for [sortByCols]. True == ascending. |
rowMask | null | BitSet | null | Mask of the rows to sort. Result array will contain [rowIndexes.length] elements. |
Returns
Int32Array
Source
getTableInfo()
getTableInfo():
TableInfo
Returns
Source
getTag()
getTag(
tag
):null
|string
Returns the value of the specified tag, or null if it does not exist.
Parameters
Parameter | Type |
---|---|
tag | string |
Returns
null
| string
Source
groupBy()
groupBy(
columnNames
):GroupByBuilder
Begins building a query, using the specified columns as keys.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
columnNames | string [] | [] | Names of the columns to be used as keys. |
Returns
Source
join()
join(
t2
,keyColumns1
,keyColumns2
,valueColumns1
,valueColumns2
,joinType
,inPlace
):DataFrame
Merges two tables by the specified key columns.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
t2 | DataFrame | undefined | a table to join |
keyColumns1 | string [] | undefined | key column names from the first table |
keyColumns2 | string [] | undefined | key column names from the second table |
valueColumns1 | null | string [] | null | column names to copy from the first table. Pass null to add all columns, an empty array [] to not add any columns, or an array with column names to add them specifically. |
valueColumns2 | null | string [] | null | column names to copy from the second table |
joinType | "left" | "right" | "inner" | "outer" | JOIN_TYPE.INNER | inner, outer, left, or right. See [DG.JOIN_TYPE] |
inPlace | boolean | false | merges content in-place into the source table |
Returns
Sample: https://public.datagrok.ai/js/samples/data-frame/join-link/join-tables
Source
onEvent()
onEvent(
event
):Observable
<any
>
Parameters
Parameter | Type |
---|---|
event | string |
Returns
Observable
<any
>
Source
row()
row(
rowIndex
):Row
Returns i-th row. NOTE: Do not use in performance-critical paths, consider accessing values via the Column instance.
Parameters
Parameter | Type |
---|---|
rowIndex | number |
Returns
Source
set()
set(
name
,idx
,value
):void
Sets idx-th value of the specified columns.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | Column name. |
idx | number | Row index. |
value | any | Value. |
Returns
void
Source
setTag()
setTag(
tag
,value
):DataFrame
Sets a tag to the specified value.
Parameters
Parameter | Type | Description |
---|---|---|
tag | string | Key. |
value | string | Value. |
Returns
Source
toByteArray()
toByteArray():
Uint8Array
Exports dataframe to binary
Returns
Uint8Array
Source
toCsv()
toCsv(
options
?,grid
?):string
Exports the content to comma-separated-values format.
Parameters
Parameter | Type | Description |
---|---|---|
options ? | CsvExportOptions | |
grid ? | Grid | if specified, takes visible columns, column and row order from the grid. |
Returns
string
Source
toCsvEx()
toCsvEx(
options
?,grid
?):Promise
<string
>
Exports the content to comma-separated-values format asynchronously with converting the molblock columns to smiles if specified.
Parameters
Parameter | Type | Description |
---|---|---|
options ? | CsvExportOptions | |
grid ? | Grid | if specified, takes visible columns, column and row order from the grid. |
Returns
Promise
<string
>
Source
toJson()
toJson():
any
[]
Exports the content to JSON format
Returns
any
[]
Source
toString()
toString():
string
Returns
string
Source
unpivot()
unpivot(
copyColumnNames
,mergeColumnNames
,categoryColumnName
,valueColumnName
):DataFrame
Unpivots the table (converts from 'wide' representation with many columns to 'tall and skinny').
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
copyColumnNames | string [] | undefined | columns to copy |
mergeColumnNames | string [] | undefined | columns to merge. Column name will become a value in the [categoryColumnName] column, and column value will become a value in the [valueColumnName] column. |
categoryColumnName | string | 'Category' | |
valueColumnName | string | 'Value' |
Returns
Source
create()
static
create(rowCount
):DataFrame
Creates a DataFrame with the specified number of rows and no columns.
Parameters
Parameter | Type | Default value |
---|---|---|
rowCount | number | 0 |
Returns
Source
fromByteArray()
static
fromByteArray(byteArray
):DataFrame
Parameters
Parameter | Type |
---|---|
byteArray | Uint8Array |
Returns
Source
fromColumns()
static
fromColumns(columns
):DataFrame
Creates a DataFrame from the specified columns. All columns should be of the same length.
Parameters
Parameter | Type |
---|---|
columns | Column <any , any >[] |
Returns
Source
fromCsv()
static
fromCsv(csv
,options
?):DataFrame
Constructs DataFrame from a comma-separated values string
Parameters
Parameter | Type | Description |
---|---|---|
csv | string | The content of the comma-separated values file. |
options ? | CsvImportOptions |
Returns
https://dev.datagrok.ai/script/samples/javascript/data-frame/construction/create-from-csv
Source
fromJson()
static
fromJson(json
):DataFrame
Constructs DataFrame from the specified JSON string.
Parameters
Parameter | Type | Description |
---|---|---|
json | string | JSON document. |
Returns
https://dev.datagrok.ai/script/samples/javascript/data-frame/construction/create-from-json
Source
fromObjects()
static
fromObjects(list
):undefined
|DataFrame
Creates a [DataFrame] from a list of objects by using object keys as column names, and object values as values.
NOTE: The implementation converts the values to strings first and then parses it, so do not use this method in performance-critical paths (for instance when the number of objects could be big), consider using fromColumns instead.
Parameters
Parameter | Type | Description |
---|---|---|
list | object [] | List of objects. |
Returns
undefined
| DataFrame
https://dev.datagrok.ai/script/samples/javascript/data-frame/construction/create-from-objects
Source
fromProperties()
static
fromProperties(properties
,rows
):DataFrame
Creates a DataFrame from the specified properties with the specified row count.
Parameters
Parameter | Type | Default value |
---|---|---|
properties | Property [] | undefined |
rows | number | 0 |