An introduction to Python for statisticians and data scientists who already work in R. The focus is on where the two languages differ, the pitfalls R users tend to hit, and the core Python data-science libraries, with each concept related back to its R equivalent.
import pandas as pd
(penguins
.groupby("species")
["body_mass_g"]
.mean())
Approach
Learn Python by way of R
The workshop assumes you're already comfortable in R, so it doesn't start from scratch. Each concept is introduced alongside its R equivalent, keeping the focus on what actually differs in Python rather than on the fundamentals of data analysis.
Built on what you know
Every idea is shown side by side with its R or tidyverse counterpart, from vectors to group_by.
Common pitfalls
0-based indexing, 2**3 vs 2^3, copy-vs-reference, and mutable defaults: the differences that most often catch R users.
Core libraries
NumPy, pandas, Matplotlib, seaborn, StatsModels, and scikit-learn, the main libraries for data analysis in Python.
Hands-on throughout
Code along in JupyterLab or Colab using the workshop notebooks, with full solutions provided.
Curriculum
What we'll cover
The material runs from the language fundamentals through the data-science workflow, split roughly evenly across the two sessions.
Session 1
Python fundamentals & NumPy
The language itself, then array computing.
01Basic syntaxOperators, strings, and import statements
02Data structuresLists, tuples, and dictionaries
03Control flow & functionsLoops, list comprehensions, conditionals
04NumPyArrays, vectorized ops, boolean indexing, random numbers
05MatplotlibFigures, axes, and the plotting basics
Session 2
The data-science stack
From wrangling to modeling and prediction.
01pandasSelecting, filtering, GroupBy, joins, method chaining, missing data
03StatsModels & SciPyRegression, distributions, and hypothesis tests
04scikit-learnThe fit / predict / score machine-learning workflow
05OOP & duck typingClasses, dunder methods, and Pythonic idioms
Materials
Workshop materials
Slides, both hands-on notebooks with solutions, and a printable R to Python cheat sheet. Open the notebooks in Colab for zero setup, or view them on GitHub. To work on your own computer, download everything in one file.
Ten sections of side-by-side R and Python syntax for quick reference.
Syntax & operators, data types and structures, control flow, functions, NumPy, pandas vs dplyr, Matplotlib & seaborn vs base R and ggplot2, statistical modeling, and the classic Python pitfalls for R users.
Doing these ahead of time means we can start on the material right away.
1Take the background survey
A short survey on your background and what you'd like to get out of the day. It helps me set the pace and choose relevant examples. Please complete it when you have a moment.
Nothing to install. From the Materials section, click Open in Colab on either notebook and start coding in your browser. A free Google account is all you need.
Option B: Run on your own computer JupyterLab
No typing required. Download one file, unzip it, and double-click the launcher for your computer. It installs Python and everything else for you.
Unzip it. On Windows, right-click the downloaded file and choose Extract All (please don't skip this step). On a Mac, double-click it.
Open the new python4r-main folder and double-click the launcher:
Windows: START-HERE-Windows.bat
Mac: START-HERE-Mac.command
The first time only, your computer may ask permission before running it:
Mac: if it is blocked, control-click (or right-click) the file, choose Open, then click Open in the dialog. If there is no Open button, go to System Settings > Privacy & Security and click Open Anyway.
Windows: if you see "Windows protected your PC", click More info, then Run anyway.
That is all. The first run downloads Python and the course packages, so give it 5 to 10 minutes and leave the window open. JupyterLab then opens in your browser. Whenever you want to work on the material again, just double-click the same file.