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
getcurrentCell():Cell
Current cell. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
setcurrentCell(cell):void
Current cell. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Parameters
| Parameter | Type |
|---|---|
cell | Cell |
Returns
Source
currentCol
getcurrentCol():Column<any,any>
Current column. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
setcurrentCol(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
getcurrentRow():Row
Current row. Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
setcurrentRow(row):void
Parameters
| Parameter | Type |
|---|---|
row | Row |
Returns
Source
currentRowIdx
getcurrentRowIdx():number
Index of the current row.
setcurrentRowIdx(idx):void
Parameters
| Parameter | Type |
|---|---|
idx | number |
Returns
number
Source
dialogs
getdialogs():DataFrameDialogHelper
Returns
Source
id
getid():string
Id of the dataframe.
setid(id):void
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
string
Source
meta
getmeta():DataFrameMetaHelper
A helper to conveniently access certain metadata properties stored in tags
Returns
Source
mouseOverRowIdx
getmouseOverRowIdx():number
Index of the mouse-over row.
setmouseOverRowIdx(idx):void
Parameters
| Parameter | Type |
|---|---|
idx | number |
Returns
number
Source
name
getname():string
Name of the dataframe.
setname(s):void
Parameters
| Parameter | Type |
|---|---|
s | string |
Returns
string
Source
onColumnNameChanged
getonColumnNameChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onColumnSelectionChanged
getonColumnSelectionChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onColumnsAdded
getonColumnsAdded():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onColumnsChanged
getonColumnsChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onColumnsRemoved
getonColumnsRemoved():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onCurrentCellChanged
getonCurrentCellChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Returns
Observable<any>
Source
onCurrentColChanged
getonCurrentColChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Returns
Observable<any>
Source
onCurrentRowChanged
getonCurrentRowChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/current-elements
Returns
Observable<any>
Source
onDataChanged
getonDataChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onFilterChanged
getonFilterChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onMetadataChanged
getonMetadataChanged():Observable<EventData<MapChangeArgs<string,string>>>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable <EventData <MapChangeArgs<string, string>>>
Source
onMouseOverColChanged
getonMouseOverColChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onMouseOverRowChanged
getonMouseOverRowChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onMouseOverRowGroupChanged
getonMouseOverRowGroupChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onNameChanged
getonNameChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onRowsAdded
getonRowsAdded():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onRowsFiltered
getonRowsFiltered():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onRowsFiltering
getonRowsFiltering():Observable<any>
Returns
Observable<any>
Source
onRowsRemoved
getonRowsRemoved():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onSelectionChanged
getonSelectionChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
onSemanticTypeDetected
getonSemanticTypeDetected():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/advanced/semantic-type-detection
Returns
Observable<any>
Source
onSemanticTypeDetecting
getonSemanticTypeDetecting():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/advanced/semantic-type-detection
Returns
Observable<any>
Source
onValuesChanged
getonValuesChanged():Observable<any>
Sample: https://public.datagrok.ai/js/samples/data-frame/events/events
Returns
Observable<any>
Source
plot
getplot():DataFramePlotHelper
A helper for creating plots for this dataframe
Returns
Source
rowCount
getrowCount():number
Returns number of rows in the table.
Returns
number
Source
selection
getselection():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[]
Converts the contents to array of objects, with column names as keys. Keep in mind that the internal DataFrame format is far more efficient than JSON, so use it only as a convenience for working with relatively small datasets.
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()
staticcreate(rowCount,name?):DataFrame
Creates a DataFrame with the specified number of rows and no columns.
Parameters
| Parameter | Type | Default value |
|---|---|---|
rowCount | number | 0 |
name? | string | undefined |
Returns
Source
fromByteArray()
staticfromByteArray(byteArray):DataFrame
Parameters
| Parameter | Type |
|---|---|
byteArray | Uint8Array |
Returns
Source
fromColumns()
staticfromColumns(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()
staticfromCsv(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()
staticfromJson(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()
staticfromObjects(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()
staticfromProperties(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 |