Professional Python project: automation with loops and branching.
My name is Delfina Sandoval. I am using this project to develop my Python skills and learn how automation, loops, branching, data analysis, logging, and visualization work together in a professional projet.
This course builds capabilities through working projects. Durable skills are grounded in real work: setting up a professional environment, reading and running code, understanding the logic, and pushing work to a shared repository. Each example is a professional Python project.
Complete Workflow A: Set Up Your Machine in pro-analytics-02.
Explore data while learning some Python basics like branching and repetition. Analysts often repeat logic (e.g. do the same thing for each observation/row in a dataset) and branch based on conditions. For example, if a missing value is detected, then we apply special instructions.
Python helps automate our analysis. We will use:
- a
forloop to repeat work for each item in a list - a list comprehension to transform one list into another
if / elif / elseto branch based on conditions- a
whileloop to repeat work while a condition is true
Selected group column: species
Reason for choosing this group:
The species column has a small number of unique values. There are three unique species, so a for loop can process and log each one.
Selected measurement column: bill_length_mm
Reason for choosing this measurement:
Bill length varies across penguins. There is no fixed cutoff, so we'll calculate the average and assign a classification depending on a threshold around the average value.
Sample bill_length_mm: 39.1
Short threshold multiplier: 0.9
Long threshold multiplier: 1.1
Short threshold: 39.529736842105265
Long threshold: 48.31412280701755
First row bill_length_mm classification: SHORT
Max records to process: 10
Stream wait seconds: 1
See project.log for more.
The project creates a histogram showing the distribution of the selected numeric measurement.
- data/ - the CSV data file
- docs/ - the project narrative and documentation
- src/datafun/ - the Python instructions
- zensical.toml - update authorship & links
Follow the step-by-step workflow guide carefully.
Why? Because getting a Python project running your machine requires many parts working together - and once it runs, it makes everything else possible.
Challenges are expected. Sometimes instructions may not quite match your operating system. When issues occur, share screenshots, error messages, and details about what you tried. Working through issues is part of implementing professional projects.
After completing Phase 1. Start & Run, you'll have the example project,
running on your machine.
A new file project.log will appear in the root project folder
and running the example script will print out:
===================================
END main() - Executed successfully!
===================================The commands below are used in the workflow guide above. They are provided here for convenience.
Follow the guide for the full instructions.
Show command reference
Open a machine terminal in your Repos folder,
change directory (cd) into the new folder,
and run code . to open only this example project in VS Code:
git clone https://github.com/sandoval9713/datafun-02-automation
cd datafun-02-automation
code .These are listed for convenience. For best results, follow the detailed instructions in pro-analytics-02 guide.
Use VS Code menu option Terminal / New Terminal to open a VS Code terminal
in the root project folder.
Copy each command, paste into your terminal, and hit ENTER,
to run each command one at a time.
uv self update
uv python pin 3.14
uv python install
uv lock --upgrade
uv sync
uv run pre-commit install
uv run pre-commit autoupdate
git add -A
uv run pre-commit run --all-files
# repeat if changes were made by pre-commit tasks
git add -A
uv run pre-commit run --all-files
# run the module
uv run python -m datafun.app
# do chores
uv run ruff format .
uv run ruff check . --fix
uv run ty check
uv run python -m pytest
uv run python -m zensical build
# save progress as you work
git add -A
git commit -m "your message here"
# repeat if changes were made (try the UP ARROW)
git add -A
git commit -m "your message here"
git push -u origin main- Use the UP ARROW and DOWN ARROW in the terminal to scroll through past commands.
- Use
CTRL+fto find (and replace) text within a file.
- You do not need to add to or modify
tests/. Tests are recommended and provided for example only. - Many files are silent helpers. Explore as you like, but most files are never touched.
- You do NOT need to understand everything; let understanding build over time.
If VS Code does not automatically use the new .venv environment:
- Open the Command Palette (
Ctrl+Shift+P). - Run Python: Select Interpreter.
- Select the interpreter from this project's
.venvfolder.
If VS Code still does not recognize the environment or newly installed tools:
- Open the Command Palette (
Ctrl+Shift+P). - Run Developer: Reload Window.
If you see something like this in your terminal: >>> or ...
You accidentally started Python interactive mode.
It happens.
Press Ctrl c (both keys together) or Ctrl+Z then Enter on Windows.
This project is licensed under the MIT License.
For the final project, I changed the grouping column from species' to island' while continuing to analyze body_mass_g. The island column has three unique values-Biscoe, Dream, and Torgersen-so the program can process each island with a for loop. This helps explore penguin body mass in the context of the islands where the penguins were observed.
For my technical modification, I changed the measurement from bill_length_mm' to body_mass_g'. I chose body mass because it is useful numeric measurement for comparing penguin sizes. After running the project, the histogram showed body masses ranging from about 2,700 to 6,300 grams, with many penguins grouped near 3,500 to 4,000 grams. The different clusters may be influenced by the differences among the penguin species.
