# Flat Files Data Guide – Filtering by exchange_symbol (Isolating Instruments from OHLCV Data)

## Flat Files Data Guide – Filtering by exchange_symbol (Isolating Instruments from OHLCV Data)

Flat Files contain **multiple instruments in a single file**, even when scoped to one exchange. To analyze a specific asset (e.g., `SWVL`, `TSM`), you must filter by `exchange_symbol`.

This guide shows how to properly isolate and export specific instruments.

## 🧠 Understanding the Data Structure

Each row represents **one instrument (symbol) for a given time period**.

### Sample Data

```
id_exchange;exchange_symbol;time_period_start;time_period_end;time_open;time_close;price_open;price_high;price_low;price_close;volume_traded;trades_count
IEXG;SWVL;2026-02-02T13:00:00.0000000;2026-02-02T13:01:00.0000000;2026-02-02T13:00:01.1326619;2026-02-02T13:00:59.9800186;3.03;3.19;2.97;3.17;4708;57
IEXG;TSM;2026-02-02T13:00:00.0000000;2026-02-02T13:01:00.0000000;2026-02-02T13:00:01.1899337;2026-02-02T13:00:09.4006344;329.44;329.73;329.44;329.69;870;28
IEXG;GLL;2026-02-02T13:00:00.0000000;2026-02-02T13:01:00.0000000;2026-02-02T13:00:01.1973889;2026-02-02T13:00:53.9836106;20.36;20.71;20.33;20.71;8325;6
IEXG;SGOV;2026-02-02T13:00:00.0000000;2026-02-02T13:01:00.0000000;2026-02-02T13:00:01.4371872;2026-02-02T13:00:05.8175414;100.38;100.38;100.38;100.38;561;3
IEXG;BMNR;2026-02-02T13:00:00.0000000;2026-02-02T13:01:00.0000000;2026-02-02T13:00:01.5840479;2026-02-02T13:00:01.5840479;22.61;22.61;22.61;22.61;100;1
IEXG;SOXX;2026-02-02T13:00:00.0000000;2026-02-02T13:01:00.0000000;2026-02-02T13:00:02.0367595;2026-02-02T13:00:02.0367595;343.4;343.4;343.4;343.4;80;1
```

### 🔑 Key Columns

* `id_exchange` → Exchange (e.g., `IEXG`)
* `exchange_symbol` → Instrument (e.g., SWVL, TSM, GLL) 
* `time_period_start/end` → Candle interval
* `price_open/high/low/close` → OHLC prices
* `volume_traded`, `trades_count` → activity

## ❗ Why Filtering is Helpful

Even though the file is:

```
E-IEXG (one exchange
```

It still contains multiple exchange_symbol values (SWVL, TSM, GLL, etc.)

👉 Without filtering, you are analyzing **multiple instruments mixed together**, which leads to incorrect results.

## 🔍 Step 1: Load the Data

### 🐍 Python (Pandas)

```python
import pandas as pd

df = pd.read_csv("D-20260202.csv", delimiter=";")
```

## 🎯 Step 2: Filter by a Single `exchange_symbol`

```python
filtered = df[df["exchange_symbol"] == "SWVL"]

print(filtered)
```

## 📁 Step 3: Save to a New File

```python
filtered.to_csv("SWVL.csv",index=False)
```

👉 This creates a new file containing only `SWVL` data

## 🔢 Step 4: Filter Multiple Symbols

```python
filtered=df[df["exchange_symbol"].isin(["SWVL","TSM","GLL"])]
```

### Save multiple-symbol dataset

```python
filtered.to_csv("selected_symbols.csv",index=False)
```

## 🔄 Step 5: (Optional) Automate Per-Symbol Export

Split the file into **one file per symbol**:

```python
for symbol in df["exchange_symbol"].unique():
    subset = df[df["exchange_symbol"] == symbol]
    subset.to_csv(f"{symbol}.csv", index=False)
```

👉 Output:

```
SWVL.csv
TSM.csv
GLL.csv
SGOV.csv
BMNR.csv
SOXX.csv
```

## ⚠️ Common Mistakes

### ❌ Forgetting quotes for strings

Wrong:

```python
df["exchange_symbol"]==SWVL
```

Correct:

```python
df["exchange_symbol"]=="SWVL"
```

### ❌ Not saving the output

print(filtered)# only displays

👉 You must use:

to_csv()  


### ❌ Wrong delimiter

Wrong:

```python
pd.read_csv("file.csv")
```

Correct:

```python
pd.read_csv("file.csv",delimiter=";")
```

## 💡 Best Practices

* Always filter before analysis
* Use `.isin()` for multiple symbols
* Save filtered outputs for reuse
* Validate results using `.unique()`

## 🎯 Key Takeaway

Each Flat File is:

One exchange → Many symbols → One time interval

👉 Filtering by `exchange_symbol` is a helpful first step before any meaningful analysis.