C3 AI Documentation Home

Pivot

Create pivot tables in Visual Notebooks.

Configuration

FieldDescription
Name (Optional) default=noneA user-specified node name displayed in the workspace
Filter Fields default=noneFilter to limit the data processed Optionally choose a field and a qualifier on that field, to limit the amount of data processed.
Column Fields default=noneValue of the column headers Specify the column headers of your pivot table with this field. Each column is named after one value of this field.
Row Fields default=noneColumn header for the first column Optionally specify the column header for the first column of your pivot table.
Value Fields RequiredData to process Choose which data to be processed and displayed in the pivot table.

Node Inputs/Outputs

InputA Visual Notebooks dataframe
OutputA dataframe reordered as a pivot table

Example dataframe output

Figure 1: Example pivot node output

Example

For the examples, we will use an input node that contains shipping data for individual orders. Each row represents one shipping order, and contains an order number, a destination for the shipment, freight charge, the price of the order, and the payment method for the order. The data is shown in the figure that follows.

Example input data

Figure 2: Example input data

For the first example, we will generate a pivot table that shows how many shipments went to each destination. Construct the table by doing the following:

  1. Connect a Pivot node to an existing node.
  2. From the Fields section, drag "destination" to Row Fields.
  3. Drag "order numbers" to Value Fields.
  4. From within Value Fields, choose "Count".
  5. Select Run.

The pivot table generated indicates that Mexico City received five shipments.

Pivot table showing order counts for each destination

Figure 3: Pivot table showing order counts for each destination

For the next example, we will use the same pivot table used in the previous example, but we will put a data filter on it so that the table only counts orders where the price of the order is greater than $500. Construct the table by doing the following:

  1. Drag "price" to Filter Fields.
  2. Select the filter icon in Filter Fields. (The filter icon becomes visible when hovering over the field.)
  3. For the Filter by condition dialog, specify Is greater than and "500". Then select OK.
  4. Select Run.

The table has fewer rows, since Mumbai and Delhi did not have any orders priced over $500. The order count for the remaining countries is diminished, as expected.

Table showing order counts subject to a price threshold condition

Figure 4: Table showing order counts subject to a price threshold condition

A pivot table can answer more advanced questions, too. You know how many orders valued over $500 were shipped to each destination, but your data also has information on payment methods. The next example modifies the table to show how many of each of the orders over $500 were paid for by credit card, how many were paid for by payment app, and how many were paid for using a bank account. To generate the table, do the following:

  1. Using the previous table, drag "payment_method" to Column Fields.
  2. Select Run.

This more granular look at the data indicates that there were two shipments valued over $500 paid for by bank accounts, that were shipped to Cairo. Additionally, there were no shipments to Shanghai paid for by bank account or credit card.

Orders broken out according to payment method

Figure 5: Orders broken out according to payment method

So far, we have counted orders, but we can also process numerical data with one of the other functions provided. In the next example, the table is modified to present the sum of freight charges, broken out by payment method, for all orders valued over $500. Construct the table by doing the following:

  1. From Value Fields, remove "order_number".
  2. Drag "Freight_charge" into this field.
  3. Hover over Value Fields, and when the filter icon becomes visible, select it, and specify Sum as the function.
  4. Select Run.

The resulting table indicates that the sum of freight charges for orders over $500 to Mexico City paid for by bank account is $54.

Sum of freight charges broken out by payment method

Figure 6: Sum of freight charges broken out by payment method

Was this page helpful?