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.
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:
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)| order_date | North | South |
|---|---|---|
| 2026-01 | 360.0 | 475.0 |
| 2026-02 | 285.0 | 280.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.
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.
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.
- Python for Data Analysis, 3rd edition (open edition) ↗Written by pandas' creator. The 3rd edition is published as an open-access HTML version on the author's site; the code examples are MIT-licensed, and the text itself may not be copied. Print and DRM-free e-book are sold separately.wesmckinney.com
- Python Data Science Handbook ↗Jake VanderPlas's full text, covering IPython, NumPy, pandas, Matplotlib and scikit-learn as Jupyter notebooks. Text is CC-BY-NC-ND and code is MIT, per the site.jakevdp.github.io
- Automate the Boring Stuff with Python ↗Al Sweigart's book, free to read online under a Creative Commons license. Not data science, but the right place to learn files, strings and loops through small useful scripts.automatetheboringstuff.com
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.
- Kaggle Learn: Python ↗A compact Python course with exercises in the browser. Kaggle's course pages say Learn courses are no cost and list an estimated time to earn the certificate.kaggle.com
- Kaggle Learn: Pandas ↗Creating, reading and writing data, then indexing, grouping and cleaning. Kaggle lists it at an estimated four hours.kaggle.com
- CS50's Introduction to Programming with Python ↗Harvard's course, open to anyone as OpenCourseWare with a verified certificate available separately. Aimed at people with or without prior programming experience.cs50.harvard.edu
- 10 minutes to pandas ↗The official quick tour. Skim it after the Kaggle course to see the vocabulary from the maintainers.pandas.pydata.org
- pandas user guide: group by (split-apply-combine) ↗The operation in the example above, explained in depth. Worth reading once you have used groupby ten times.pandas.pydata.org
- NumPy: the absolute basics for beginners ↗Arrays, shapes and vectorized math from the NumPy docs; read it when pandas operations start to feel like magic.numpy.org
- Install Jupyter ↗Project Jupyter's install page. Notebooks are how most data work is explored and shared.jupyter.org
04 · PICKING THE TOOL
Which layer for which task
| Task | Tool | Why |
|---|---|---|
| Rename files, loop over a folder | Plain Python, pathlib | No tables involved. |
| Math on a million numbers | NumPy array | Vectorized operations avoid Python-level loops. |
| Filter, join, group a table with named columns | pandas DataFrame | Labeled columns, dates, missing-value handling built in. |
| Data already in a database | SQL first, pandas after | Do the filtering where the data lives. See the SQL guide. |
| Fit a model | scikit-learn | See the machine learning guide. |
05 · TRY IT
A two-week plan
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.