C3 AI Documentation Home

Extract Value from Array

Extract only selected values of interest from a column of type Array, consisting of multiple entries and possibly nested Arrays, into new columns.

Arrays in Visual Notebooks can contain the following combinations of data types:

  • Strings, numeric (i.e., double, integer, long), timestamp and Boolean (Note: all data is converted to string)
  • Multiple arrays

If an Array consists entirely of numeric values and has only one level (i.e., it is one-dimensional), it is labeled as type Vector.

Data analysis often involves a large number of concurrent mathematical operations on structured data (i.e., stored in a database and indexable by row and column). Matrix algebra is most commonly used to perform these operations efficiently. Arrays are equivalent to row vectors, and they complement the efficient column operations built into Visual Notebooks. Several transformations are provided for manipulating Arrays, including creating Arrays, extracting values from Arrays and disassembling Arrays.

Configuration

FieldDescription
Name default=noneName of the node: A user-specified node name, displayed in the canvas and in the dataframe as a tab.
Select Array Column to Extract RequiredSelect single column of type Array: Select the input Array column from which to extract a specific field.
Position to Extract RequiredElement to extract from the Array column: Enter a non-zero integer corresponding to the index of the entry to extract. The index of the first entry is "1". Indexing can also be done starting with the last entry, which has position "-1".
Output Column Name default=DefaultDesired name for the output column: Select "Default" if you want the column name to be of the format "_" where n ≥ 1 is an integer that increments by one for each column. Select "Custom" to enter a custom column name.
Drop Original Column(s) default=OnToggle indicating whether the selected input column(s) should be dropped from the output: Leave the switch on to delete the Array column(s) from which output columns are extracted. Toggle the switch off to keep the selected column(s).

Node Inputs/Outputs

InputA Visual Notebooks dataframe
OutputA dataframe with extracted values

Example dataframe output

Figure 1: Example dataframe output

Examples

The data shown in Figure 2 is used in the following examples. It contains operating parameters for a number of gas turbine powered generators, including temperatures, pressures, speed, and output power components. We would like to extract the Combustion Temperature and Output Current from a single nested array containing all of the parameters.

Example input data

Figure 2: Example input data

To create the nested array shown in Figure 2 from the linked file, complete Example 2 - Nested Arrays in the documentation for the Assemble Array node. Then, follow the steps below to extract the Combustion Temperature and Output Current:

  1. Connect an Extract Value from Array node to an existing node. In this case, it should be connected to an Assemble Array node called "Parameters".
  2. Enter "Extract Temps and Power" for Name.
  3. Select "Parameters" for Select Array Column to Extract and "1" for Position to Extract. Toggle "Custom" for Output Column Name and enter "Temps" for the column name.
  4. Click + Additional Value to specify another value to extract.
  5. Select "Parameters" for Select Array Column to Extract and "4" for Position to Extract. Toggle "Custom" for Output Column Name and enter "Power_Comp" for the column name.
  6. Toggle Drop Original Column off and click Run.

After running the node, the temperatures and power components are extracted as separate columns, which are shown in Figure 3. Note that only a single level in the nested Array is extracted. Given the input is a nested Array of numerical values, the output columns are Vectors.

Extracting temperature and power component Vectors from a nested Array

Figure 3: Extracting temperature and power component Vectors from a nested Array

We now extract the Combustion Temperature and Output Current directly from these Vectors:

  1. Connect another Extract Value from Array node to the previous one.
  2. Enter "Extract CT and OC" for Name.
  3. Select "Temps" for Select Array Column to Extract and "2" for Position to Extract. Toggle "Custom" for Output Column Name and enter "Comb_Temp" for the column name.
  4. Click + Additional Value to specify another value to extract.
  5. Select "Power_Comp" for Select Array Column to Extract and "2" for Position to Extract. Toggle "Custom" for Output Column Name and enter "I_out_A" for the column name.
  6. Toggle Drop Original Column off and click Run.

After running the node, the Combustion Temperature and Output Current are extracted as type Double in separate columns, which are shown in Figure 4.

Extracting Combustion Temperature and Output Current parameters

Figure 4: Extracting Combustion Temperature and Output Current parameters

Was this page helpful?