← Dashboard

data science / python

Python for Data Science: From a Raw CSV to a Monthly Revenue Table

You do not need to finish a general Python course before touching data. This guide starts with a messy six-line CSV, cleans it with pandas, and produces a revenue table, then points to the free books and courses that go deeper, and flags what changed in pandas 3.

updated Nov 2026·an 11-minute read·code run on Python 3.14, pandas 3.1

Data work in Python rests on three layers. Plain Python (lists, dictionaries, functions, loops) moves things around. NumPy gives you fast arrays. pandas puts labeled tables on top of NumPy, and that table, the DataFrame, is where most analysis happens. The usual mistake is to study the first layer for months before seeing the third. A better order is to learn just enough Python to read a script, then work on real tables and fill in gaps as they appear. The example below is that approach in miniature.

01 · THE WORKED EXAMPLE

Clean a CSV and answer a question in seven lines

A small shop exports orders as a CSV. It has one duplicated row and one missing price. The question is revenue per month per region. This script ran as written:

revenue.pypandas 3.1, Python 3.14
import io
import pandas as pd

raw = """order_date,region,product,units,price
2026-01-03,North,Desk,2,180
2026-01-03,North,Desk,2,180
2026-01-09,South,Chair,5,
2026-02-14,North,Chair,3,95
2026-02-20,South,Desk,1,180
2026-02-21,South,Lamp,4,25
"""
df = pd.read_csv(io.StringIO(raw), parse_dates=["order_date"])
df = df.drop_duplicates()
df["price"] = df["price"].fillna(95)          # Chair list price
df["revenue"] = df["units"] * df["price"]
monthly = (df.groupby([df["order_date"].dt.to_period("M"), "region"])["revenue"]
             .sum().unstack(fill_value=0))
print(monthly)
Output
order_dateNorthSouth
2026-01360.0475.0
2026-02285.0280.0

Check the arithmetic: North in January is one Desk order of 2 x 180 = 360 once the duplicate is dropped. South in January is 5 chairs at the filled-in 95, which is 475. Without drop_duplicates() North would read 720, and nothing would have warned you. The habit to build is to compute one cell by hand every time you write a pipeline.

WATCHThe fillna line is a decision, not a cleanup. Filling the missing price with the Chair list price is only valid because you know it. Filling with the column mean, or 0, would change the revenue figure and should be a conscious choice you can explain.

02 · WHAT CHANGED

pandas 3 changed two defaults you will notice

pandas 3.0 was released on January 21, 2026, and the current documentation is for 3.1. Two changes from the release notes show up in everyday code. First, text columns now use a dedicated string dtype by default instead of NumPy object; in the script above, df.dtypes reports region as str. Second, copy-on-write is the consistent behavior: each DataFrame or Series acts as its own copy, so the old chained-assignment warnings and the habit of sprinkling .copy() are no longer needed.

This matters when you follow older material. Many tutorials, and the 2022 edition of Python for Data Analysis, were written for pandas 1.x and show object dtypes and defensive copying. The code mostly still runs, but the printed output will differ from what you see on screen. When a result does not match the book, check the version before assuming you made a mistake.

TIPPin your tools in a virtual environment. Create one with python -m venv .venv and install into it. As of this writing python.org offers 3.15.2, but PyTorch's Windows install page lists support for Python 3.10 to 3.14, so the newest interpreter is not always the one your whole stack supports. The numeric stack used for this page installed cleanly on 3.14.

03 · BOOKS AND COURSES

Free books and courses, by what they are good for

Two free books cover the PyData stack end to end, and they complement each other: Wes McKinney, who created pandas, writes for people who want to get things done in it; Jake VanderPlas writes a tour of the core libraries.

For structured practice, the Kaggle micro-courses are short and run in the browser, and CS50P is the rigorous option if you want a proper programming foundation first.

04 · PICKING THE TOOL

Which layer for which task

When to reach for what
TaskToolWhy
Rename files, loop over a folderPlain Python, pathlibNo tables involved.
Math on a million numbersNumPy arrayVectorized operations avoid Python-level loops.
Filter, join, group a table with named columnspandas DataFrameLabeled columns, dates, missing-value handling built in.
Data already in a databaseSQL first, pandas afterDo the filtering where the data lives. See the SQL guide.
Fit a modelscikit-learnSee the machine learning guide.

05 · TRY IT

A two-week plan

TRY ITDays 1 to 4: Kaggle's Python course. Days 5 to 8: Kaggle's Pandas course, retyping the exercises instead of pasting. Days 9 to 12: take a CSV you care about (your bank export, a public city dataset) and rebuild the revenue example for it: parse dates, remove duplicates, group by month. Compute one number by hand to check it. Days 13 and 14: read the relevant chapter of McKinney's book on the same operations and note what you would now do differently.

06 · FAQ

Frequently asked questions

Do I need to learn all of Python before learning pandas?

No. Learn variables, lists, dictionaries, functions and loops, which takes a few days, then start on real tables. Going back to fill gaps while you work on data sticks better than months of general Python study.

What changed in pandas 3.0?

pandas 3.0, released January 21, 2026, makes a dedicated string type the default for text columns and uses copy-on-write consistently, so a DataFrame derived from another behaves as its own copy. Older tutorials may show object dtypes and defensive copies that are no longer needed.

Which free book should I start with?

Start with the Kaggle Python and Pandas courses, then read Python for Data Analysis, 3rd edition, which its author publishes as an open-access edition online. Use the Python Data Science Handbook as a second reference for NumPy, Matplotlib and scikit-learn.

Should I use the newest Python version for data science?

Not automatically. Check that every library you need supports it first. For example, PyTorch's Windows install page lists Python 3.10 to 3.14 at the time of writing, even though newer releases exist, so a slightly older interpreter is often the safer choice.

Keep going

Once you can load and reshape data, the next steps are plotting and modeling.