> For the complete documentation index, see [llms.txt](https://calctree.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calctree.gitbook.io/docs/calculations/creating-calculations/variable-display-types/selection-dropdown-list/using-csv-data-in-selection-lists.md).

# Using CSV Data in Selection lists

Connect a CSV file to Selection lists in CalcTree using Python for structured data filtering and selection.

This guide walks you through how to read structured data from a CSV file and build dependent Selection lists in CalcTree using Python and math variables. The pattern is commonly used in workflows that require a selection of material or section type and then extracting specific properties for the selection for use in calculations.

### 1. Load and Structure Your Data

Upload your CSV file (e.g. `CT - Standard Steel Section Capacity - DB.csv`) using the **Files** tab, then read it into a structured format using pandas. Learn more [here](https://calctree.gitbook.io/docs/create-calculations/csv-files).

Once this is complete, create a new Python node, and add the below code.

```python
import pandas as pd 

def read_csv(csv):
    return pd.read_csv(ct.page_files[csv])

section_db = read_csv("CT - Standard Steel Section Capacity - DB.csv") \
    .astype('object') \
    .fillna("") \
    .to_dict("records")
```

This loads your CSV into a list of dictionaries (`records`) that are easy to filter by field name.

{% hint style="info" %}
In CalcTree, we recommend using Python dictionaries instead of pandas DataFrames for better performance. While DataFrames are supported, they are heavier and better suited to large-scale data processing outside of interactive calculation pages.
{% endhint %}

### 2. Apply the Two-Step Filter

#### 2.1 Extract Primary Filter Options

In the same code, get the unique values from a primary column (e.g. `"Type"`):

```python
type_list = list({row["Type"] for row in section_db})
```

#### 2.2 Create a Selection list

Create a new math variable in the page for the list and make it equal to `type_list`.&#x20;

`Section_Type_ = type_list`

Then in the settings for this variable, [set the visibility to 'Selection'](https://calctree.gitbook.io/docs/create-calculations/sources-and-variables/dropdown-list-parameters).

<figure><img src="https://94933883-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS1yC9mBIPsA0bB8PMGaq%2Fuploads%2FtKU6uHJwk8AgiAwWAqzp%2FScreenshot%202025-10-15%20at%204.09.16%E2%80%AFPM.png?alt=media&amp;token=ace033cc-2281-4b17-bf3d-17e7965677f6" alt=""><figcaption></figcaption></figure>

#### 2.3 Filter the Secondary Options Based on type\_list Selection

Filter the list of available `"Section"` values based on the currently selected `"Section_Type_"`.

```python
section_list = list({
    row["Section"] for row in section_db if row["Type"] == Section_Type_.upper()
})
```

Make sure the "Type" name matches the variable name you set, in this case, `Section_Type_`.

#### 2.4 Repeat step 2.2 for the new dependent list

Insert `section_list` into the page creating a new variable `Section = section_list .` Then in the settings for this variable, [set the visibility to 'list'](https://calctree.gitbook.io/docs/create-calculations/sources-and-variables/dropdown-list-parameters).&#x20;

### 3. Use the Selected Section in Your Logic

Once the user has made a selection, extract the full row from the database and use its fields in your calculation.

```python
selected_row = next((row for row in section_db if row["Section"] == Section), {})

depth = float(selected_row.get("Depth", 0))
area = float(selected_row.get("Area", 0))
moment_capacity = float(selected_row.get("M_ult", 0)) / 1000  # Nm → kNm
```

### 4. Use the Selected Item in Your Logic

Once a specific section is selected (e.g., `"UB 203x102x23"`), use it to retrieve or process further data in a Code Source 3.

### Summary

This approach lets you:

* Link a CSV database to interactive parameters
* Build dependent Selection lists (e.g. section type → section name)
* Extract and use structured data in calculations

It’s ideal for any workflow where selections narrow down from a database — like selecting standard parts, profiles, or material specs.
