flowchart LR
A("explore") -->|run|B("test")
B -->|fix|A
B --> C("explain")
C --> |refactor|A
CSCI 1109 — Practical Data Science
venv, virtualenv, conda envs).Tip
Rule of thumb: if something feels “annoying but small” in setup, it will become “huge and painful” at 1am before a deadline 😴.
Note
Goal for this module: you can reliably run notebooks, import packages, and know which Python is running your code.
Specifically, do you have v3?
py -V OR python -V OR where pythonpython3 --version OR which python3If you see a version like 3.x and an interpreter path inside your project env (not system), you’re ready.
| Method | Steps (summary) | Best for | Notes / Link |
|---|---|---|---|
| Python.org installer | Download the Windows installer; run with “Add Python to PATH”; then py -V. |
Most users; simple local install. | python.org → Windows |
| WinGet | winget install -e --id Python.Python.3 (or latest id shown by winget search Python); restart shell; py -V. |
Admin-friendly, scriptable installs. | WinGet docs |
| Miniforge (conda‑forge) | Download Miniforge exe; install; conda create -n 1109 python=3.11 -y; conda activate 1109. |
Reproducible envs; class projects. | Miniforge (conda‑forge) |
| Anaconda Distribution | Download & install Anaconda; use Anaconda Prompt; manage envs with conda. |
GUI tools + many prebuilt pkgs. | Anaconda Download |
| Method | Steps (summary) | Best for | Notes / Link |
|---|---|---|---|
| Python.org pkg | Download macOS installer; run; python3 --version. |
Simple, standalone install. | python.org downloads |
| Homebrew | brew install python → python3 --version. |
Devs already on Homebrew. | Homebrew & Python |
| Miniforge (conda‑forge) | Download .pkg or .sh; install; conda create -n 1109 python=3.11 -y; conda activate 1109. |
Repro envs; consistent with Windows/Linux. | Miniforge |
| Anaconda Distribution | Install Anaconda; manage envs with conda. |
All‑in‑one data science stack. | Anaconda Download |
| Method | Steps (summary) | Best for | Notes / Link |
|---|---|---|---|
| Ubuntu/Debian packages | sudo apt update && sudo apt install -y python3 python3-venv python3-pip |
System-managed installs. | Ubuntu dev guide (Python setup) |
| Fedora/RHEL packages | sudo dnf install -y python3 python3-pip |
System-managed installs. | Fedora docs on dnf |
| Arch btw | sudo pacman -Syu → sudo pacman -S python python-pip → verify with python --version (use python -m venv .venv for project envs) |
Arch/Manjaro users comfortable with pacman | Arch Wiki — Python |
| Miniforge (conda‑forge) | Download installer; run bash Miniforge3-...sh; conda create -n 1109 python=3.11 -y; conda activate 1109. |
Isolated, reproducible envs across distros. | Miniforge |
| Anaconda Distribution | Download installer; bash Anaconda3-...sh; conda to manage envs. |
All‑in‑one stack & course parity. | Anaconda Download |
pandas X; Project B needs pandas Y → ❌ one global install cannot satisfy both.
Tip
Freeze what you run (package), isolate where you run it (env), and your work becomes reproducible, reviewable, and shippable.
venv)python -m venv .venv
# Windows: .\.venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
python -m pip install -U pip.venv/, requirements.txt.conda create -n 1109-m02 python=3.11 pandas matplotlib -y
conda activate 1109-m02
conda env export --no-builds > environment.ymlconda-forge for breadth + consistency.pip inside the activated env if needed; avoid mixing back-and-forth.
# Stop auto-activating base on every new shell
conda config --set auto_activate_base false
# Create per-project envs (example)
conda create -n myproj python=3.11 -y
conda activate myproj
# Quick self-check
conda info --envs # active env has a * next to it (and shouldn’t be base for project work).
python -c "import sys; print(sys.executable)" #path should live in your project env.
pip --version # the path printed should also point into that same env.| venv | conda | |
|---|---|---|
| What it is | Per-project Python environment | Environment + package manager |
| Package manager | pip |
conda (you can add pip inside) |
| Non-Python deps | No (uses system/toolchain) | Yes (BLAS, HDF5, CUDA, …) |
| Binaries | PyPI wheels; success varies by OS/toolchain | Prebuilt, cross-platform binaries (e.g., conda-forge) |
| Repro artifact | requirements.txt |
environment.yml |
| Ideal for | Pure-Python stacks; lightweight apps; simple CI/CD | Data-science stacks; geospatial/ML/GPU |
| Strengths | Minimal, ubiquitous, standard | Fewer compile headaches; consistent installs across OSs |
| Watch-outs | Native builds can fail; system-pkg collisions | Channel mixing; larger footprint; avoid always-on base |
Note
Rule of thumb: If your project is pure-Python, prefer venv (+pip). If it’s binary-heavy or you need smooth cross-OS installs, prefer conda (ideally conda-forge). In both cases, export an env file so others can reproduce your results.
Two common routes — pick one per project.
A) venv (standard library)
python3 -m venv .venv
# macOS/Linux
source .venv/bin/activate
# Windows (PowerShell)
.\.venv\Scripts\Activate.ps1
python -m pip install -U pip # upgrades Pip in your env→ Export later with python -m pip freeze > requirements.txt (PyPA guide).
flowchart LR
A("explore") -->|run|B("test")
B -->|fix|A
B --> C("explain")
C --> |refactor|A
.ipynb? + modes & shortcuts.ipynb is a JSON doc: ordered cells (markdown \(\oplus\) code) + outputs + metadata.



See 🔗 here
| Keys | Action |
|---|---|
A / B |
Insert cell Above / Below |
M / Y |
Set cell to Markdown / Code |
DD |
Delete cell |
Shift-Enter |
Run & move down |
Ctrl/Cmd-Enter |
Run in place |
--- config: look: handDrawn theme: neutral handDrawnSeed: 42 # optional, for reproducible scribbles fontSize: 36em --- flowchart LR A["Notebook (.ipynb)"] -->|"sends code"| B["Kernel (specific Python env)"] B --> C["Packages (pandas, numpy, …)"] B --> D["Files + Data (csv, images,...)"] B --> E["Outputs (tables, plots, text)"]
ModuleNotFoundError (package isn’t installed in that kernel)Tip
Always verify the kernel with sys.executable (it tells you which Python is running).
Python executable: /opt/homebrew/anaconda3/bin//python
Python version: 3.9.13
From 🔗 here
http://localhost:8888) and opens a browser UI (dashboard → notebook).flowchart LR A["Browser UI"] -->|"HTTP/WebSocket"|B["Jupyter server (localhost)"] B --> |"kernel protocol"|C["Python kernel (your env)"] B --> D["File system: .ipynb, data, artifacts"]


I love
Emacs, the one true text editor.
As with all things, Jupyter notebooks run in Emacs too, but try this only if you’re playing life on 👷 Hard Mode.
See 🔗 Jupyter Emacs Universe and the 🔗 MELPA package

flowchart LR
A["Project folder"] --> B["env.yml / requirements.txt"]
B --> C{"Environment (venv or conda)"}
C -->|"kernel spec"|D["Jupyter Kernel"]
D --> E["Notebook (.ipynb)"]
C --> F["Python Script (.py)"]
E --> G["Artifacts: figures, tables"]
F --> G
C --> H["pip / conda"]
H --> C
flowchart LR A["Raw data<br>(CSV/DB/URL)"] --> B["Clean & structure<br>(tidy units)"] B --> C["Compute<br>(features, summaries)"] C --> D["Visualize"] D --> E["Claim<br>(metric + uncertainty)"] E --> F["Decision<br> (cost-aligned)"]
Question: How does outside temperature relate to hot-drink orders (per day)?
Units: temp = °C; orders = count/day.
import pandas as pd, numpy as np
import matplotlib.pyplot as plt
from io import StringIO
coffee = StringIO("""day,temp_C,orders
Mon, 3, 210
Tue, 5, 220
Wed, 7, 265
Thu, 9, 300
Fri,10, 340
Sat, 8, 310
Sun, 4, 250
""")
df = pd.read_csv(coffee)
df['orders_norm'] = df['orders'] / df['orders'].max()
print(df)
plt.figure(figsize=(6,4))
plt.scatter(df['temp_C'], df['orders'], s=80)
plt.title('Coffee orders vs temperature (°C)')
plt.xlabel('Temperature (°C)'); plt.ylabel('Orders / day')
plt.tight_layout(); plt.show() day temp_C orders orders_norm
0 Mon 3 210 0.617647
1 Tue 5 220 0.647059
2 Wed 7 265 0.779412
3 Thu 9 300 0.882353
4 Fri 10 340 1.000000
5 Sat 8 310 0.911765
6 Sun 4 250 0.735294

Interpretation prompt: Is the trend linear? What other variables might confound (weekday, rain, promotions)?
Decision hook: Stock & staffing decisions for chilly vs warm days.
import pandas as pd, numpy as np, matplotlib.pyplot as plt
np.random.seed(0)
days = pd.date_range('2025-01-01', periods=14)
visits = np.random.poisson(lam=np.linspace(80,120,14))
df = pd.DataFrame({'date':days,'visits':visits})
df['roll3'] = df['visits'].rolling(3, center=True).mean()
df['band'] = df['visits'].rolling(3, center=True).std()
print(df.head())
plt.figure(figsize=(7,4))
plt.plot(df['date'], df['visits'], 'o-', label='Daily visits')
plt.fill_between(df['date'],
(df['roll3']-df['band']).fillna(method='bfill').fillna(method='ffill'),
(df['roll3']+df['band']).fillna(method='bfill').fillna(method='ffill'),
alpha=0.3, label='±1 σ (rolling)')
plt.plot(df['date'], df['roll3'], '--', label='3-day mean')
plt.legend(); plt.title('Student engagement (visits/day)')
plt.xlabel('date'); plt.ylabel('visits/day'); plt.tight_layout(); plt.show() date visits roll3 band
0 2025-01-01 81 NaN NaN
1 2025-01-02 86 83.666667 2.516611
2 2025-01-03 84 85.666667 1.527525
3 2025-01-04 87 96.333333 18.823744
4 2025-01-05 118 103.000000 15.524175

Note
Takeaway: Smoothed trend ≠ ground truth; bands show local variability.
Decision hook: When to escalate an intervention vs wait another day.
Same code behaves differently if run out of order. That’s why Restart & Run All matters.
Experiment: Delete Cell A (above), run only Cell B. Do you get a NameError? Now Restart Kernel and Run All from the top. ✏️ Does it pass? What did we learn?
A tiny excerpt of global CO₂ (MtC = million metric tons of carbon).
Units: MtC/year; this is a toy slice to keep it lightweight.
import pandas as pd, io, matplotlib.pyplot as plt
csv = io.StringIO("""Year,Total_MtC
2015,9724
2016,9737
2017,9908
2018,10004
2019,10010
2020,9469
2021,10081
2022,10302
""")
co2 = pd.read_csv(csv)
print(co2)
co2.plot(x="Year", y="Total_MtC", marker='o', title="Global CO₂ (MtC) — tiny excerpt")
plt.ylabel("MtC / year"); plt.tight_layout(); plt.show() Year Total_MtC
0 2015 9724
1 2016 9737
2 2017 9908
3 2018 10004
4 2019 10010
5 2020 9469
6 2021 10081
7 2022 10302

Discussion: ✏️ What comparisons are valid with such a short series? What would you add (per-capita, sector breakdown, uncertainty)?
Tip
1) Inspect first (always): df.head(), df.info(), df.describe()
Tip
2) Plot early: a quick plot catches problems faster than reading 200 rows
Tip
3) Name things for meaning: co2_monthly beats df2
Tip
4) Write the takeaway in the title: make plots that explain themselves
sys.executable.venv / conda env?python -m pip install <package>Warning
If you ask for help, include:
(a) the code cell, (b) the full error, (c) output of sys.executable, (d) your OS.
sys.executable, versions)Note
We’ll soon spend less time on tooling and more time answering questions with data.
