What Python does in a data team
ShopKart's data lives in many places: order CSV files from the app, a payments API, a PostgreSQL database. Every morning someone has to collect it, clean it and load it so analysts can use it. SQL is great inside a database; Python moves data between systems and automates everything around it.
Extract
Read CSV/JSON files, call REST APIs, query databases
Transform
Clean, validate, de-duplicate, reshape (plain Python or pandas)
Load
Write Parquet, upsert into PostgreSQL or a warehouse
Run & check
Logging, retries, tests, scheduling (Airflow, Databricks jobs)
| Task | Python tool | Lesson |
|---|---|---|
| Read and write CSV, JSON | csv, json, pathlib (built in) | 5 |
| Handle bad data and failures | try/except, logging | 6 |
| Pull data from APIs | requests | 7 |
| Clean and reshape tables | pandas, Parquet | 8 |
| Load databases | psycopg (PostgreSQL), sqlite3 | 9 |
| Build and test a pipeline | argparse, pytest | 11 |
| Big data | PySpark (see our Databricks course) | - |
Step 1: Install Python
Download Python 3.12+ from python.org (Windows/macOS) or use your system's package manager. On Windows, tick “Add Python to PATH” during install. Then check it works:
$ python --version Python 3.13.14
On some systems the command is python3 instead of python.
Step 2: Create a project with a virtual environment
# a folder for the project$mkdir shopkart && cd shopkart# create a virtual environment in .venv$python -m venv .venv# activate it (macOS/Linux)$source .venv/bin/activate# activate it (Windows PowerShell)$.venv\Scripts\Activate.ps1# install the libraries this course uses$pip install pandas pyarrow requests "psycopg[binary]" pytest# save exact versions so others get the same setup$pip freeze > requirements.txt
Step 3: Your first lines of Python
Type python to open the interactive prompt (the REPL), handy for quick experiments:
print("Hello, data engineer!")Hello, data engineer!
Step 4: Your first data script
Real work lives in .py files. Create first_script.py:
# first_script.py: ShopKart's first data question
daily_sales = [1999, 4999, 1497, 2498] # one number per order today
total = sum(daily_sales)
average = total / len(daily_sales)
print(f"Orders today: {len(daily_sales)}")
print(f"Total sales: ₹{total:,}")
print(f"Average order: ₹{average:,.2f}")$ python first_script.py Orders today: 4 Total sales: ₹10,993 Average order: ₹2,748.25
#starts a comment: Python ignores it.[ ... ]is a list;sum()andlen()are built-in functions.f"...{total:,}"is an f-string: it puts values into text, with a thousands separator. Lesson 2 covers it.- Indentation matters in Python: blocks are defined by spaces (4 per level), not braces.
Notebook or script?
| Jupyter / Databricks notebook | .py script | |
|---|---|---|
| Best for | Exploring data, quick charts | Pipelines that run every day |
| Testing | Hard | Easy with pytest |
| Code review / Git | Messy diffs | Clean diffs |
| Scheduling | Possible (Databricks jobs) | Anywhere (cron, Airflow, jobs) |
The ShopKart files we'll use
Most lessons work with three small files that are messy on purpose, like real data:
| File | What's inside | Problems hidden in it |
|---|---|---|
| data/orders.csv | 10 orders | Lower-case status, extra spaces, a duplicate, a missing customer, quantity 'two' |
| data/customers.json | 5 customers with nested contact info | null phone numbers, a null city |
| data/events.jsonl | Website events, one JSON per line | Different fields per event type |
🎯 Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1Why is Python popular for data engineering?Fresher
Q2What is a virtual environment and why use it?Fresher
Q3Is Python compiled or interpreted?1–3 yrs
Q4How do you make a Python project reproducible?1–3 yrs
Key takeaways
- Python connects the systems in a data pipeline.
- Set up every project with its own virtual environment.
- Pipelines live in .py files; notebooks are for exploring.
- Next: Python's building blocks: numbers, text and None.
Frequently asked questions
Why do data engineers use Python?
Python is easy to read, has libraries for almost every data task (files, APIs, databases, pandas, Spark), and is the main language of tools like Airflow, PySpark and Databricks notebooks. It's the glue that moves data between systems.
Which Python version should I install?
A recent stable version: 3.12 or newer. This course uses Python 3.13. Avoid Python 2; it has been dead since 2020.
What is a virtual environment?
A private folder of packages for one project, so project A can use pandas 2 while project B uses pandas 3 without conflict. Create one with python -m venv .venv and activate it before installing packages.
pip, venv, uv or conda?
pip installs packages and venv creates environments: both come with Python, and this course uses them. uv is a newer, very fast tool that does both. conda is popular in data science. Learn pip + venv first.
Do I need an IDE?
Any editor works. VS Code with the Python extension is the most common free choice; PyCharm is popular too. Jupyter notebooks are great for exploring data, but pipelines live in .py files.
🧠 Quick check: Python for data engineering
1. What is a virtual environment for?
2. How do you run a script called load.py?
3. Where should pipeline code live?
4. Which is NOT a typical data engineering use of Python?