Use column inputs
Datagrok provides you with data inputs to select one or multiple columns from a dataframe.
- The
column
input parameter allows you to select one column from the dataframe. In the script, thecolumn
parameter is a string variable containing header name of the selected column. - The
column_list
input parameter allows you to select multiple columns from the dataframe. In the script, thecolumn_list
parameter is a list of strings containing header names of the selected columns.
Both of these selectors require at least one Dataframe input to choose a dataframe.
- Result
- Python
- JavaScript
#name: ColumnSelectorDemo
#description: Using column selectors
#language: python
#tags: demo, dataframe, column_selector
#input: dataframe table [Data table]
#input: column id_column [Fill this column with auto-d=generated ID]
#input: column_list data_columns [Keep this column and drop all others]
#output: dataframe new_table [New table with additional column]
new_table = table.copy()
l = len(new_table)
new_table[id_column] = [f"id_{n:04}" for n in range(l)]
new_table = new_table[ [id_column] + data_columns ]
//name: ColumnSelectorDemo
//description: Using column selectors
//language: javascript
//tags: demo, dataframe, column_selector
//input: dataframe table [Data table]
//input: column id_column [Fill this column with auto-d=generated ID]
//input: column_list data_columns [Keep this column and drop all others]
//output: dataframe new_table [New table with additional column]
const new_table = table.clone();
const l = new_table.rowCount;
new_table.col('model').init((i) => `${id_column.get(i)}_${i}`);