My First Python Project

Published on:

My first serious Python project was a small data analysis script written for a school assignment. It worked — but reading it back made my eyes water.

The Mistake: Putting Everything in One File

One 500-line main.py file. Data reading, cleaning, analysis, visualization — all tangled together. Changing one thing required understanding everything else.

# Past me
data = open('data.csv').read().split('\n')
result = []
for line in data:
    cols = line.split(',')
    if cols[2] != '' and float(cols[2]) > 0:
        result.append(float(cols[2]))
print(sum(result) / len(result))

The Lesson

If code works, that’s not enough. Someone else (or you, six months later) has to be able to read it.

Functions, modules, meaningful names — these aren’t luxuries, they’re necessities.

Present Me

How I’d write the same thing today:

import pandas as pd

def calculate_average(filepath: str, column: str) -> float:
    df = pd.read_csv(filepath)
    return df[column].dropna().mean()

Fewer lines, more meaning.