This is the finished version of the Week 3 routing workflow, here as a lifeline if you get stuck. It shows one good way to reach the goal, not the only one, so try it yourself first. The student-facing starter is simple-data-cleaning-langgraph-workflow-start.
A simple example demonstrating how to build workflows with LangGraph for data processing.
The workflow follows these steps:
- Load Data - Reads the CSV file into a pandas DataFrame
- Summarize Data - Generates comprehensive summary including:
- Statistical description (
.describe()) - Dataset info (
.info()) - Explicit missing value counts
- Statistical description (
- LLM Reasoning - Uses GPT-4o-mini to analyze the summary and decide which action to take
- Conditional Routing - Routes to appropriate cleaning node based on LLM decision
- Data Cleaning - Can execute:
- Handle Missing Values - Fills numeric missing values with column means
- Remove Outliers - Removes outliers using IQR (Interquartile Range) method
- Clean Both - Fills missing values first, then removes outliers
- Describe Data - Generates statistical summary of cleaned data
- Output Results - Prints the action taken and final summary
-
Verify Python is installed (Python 3.9 or higher required):
python --versionIf not installed, download from python.org
-
Install Poetry:
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
After installation, restart your terminal or IDE. If
poetrycommand is not found, add%APPDATA%\Python\Scriptsto your system PATH. -
Install dependencies:
poetry install
-
Set up your OpenAI API key:
copy .env.example .env
Then edit
.envand add your OpenAI API key:OPENAI_API_KEY=sk-your-key-here
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install
-
Set up your OpenAI API key:
cp .env.example .env
Then edit
.envand add your OpenAI API key:OPENAI_API_KEY=sk-your-key-here
From the project root:
poetry run python workflows/simple_clean_data_workflow.pyThe workflow will:
- Save a workflow graph visualization to
outputs/workflow_graph.png - Load data from
data/missing_and_outliers.csv(you can change this in the script) - Use an LLM to analyze the data and decide which cleaning action to take
- Execute the appropriate cleaning steps
- Display the results
.
├── README.md
├── pyproject.toml
├── .env.example
├── .gitignore
│
├── data/
│ ├── missing.csv # Data with only missing values
│ ├── outliers.csv # Data with only outliers
│ └── missing_and_outliers.csv # Data with both issues
│
├── workflows/
│ └── simple_clean_data_workflow.py # Main workflow implementation
│
└── outputs/
└── .gitkeep # Generated files (graphs, reports)
Folder Organization:
data/- Sample CSV files with different data quality issuesworkflows/- LangGraph workflow scriptsoutputs/- Generated outputs (visualizations, reports)