Python: warming up...

Reading Files Trainer

Built-in AI tutor. Stuck on a cell? Ask the helper on this page. It coaches against the cell you are running — it does not hand you the answer.

In Excel, getting data in was File > Open. In Python you do the same thing with one line of code, and you get to choose what shape the data arrives in. This page reads one small file three ways so you can see the difference. Type a line and press Shift+Enter (or click Run) to execute it. This is real Python, running in your browser.

The file

What we are reading

A tiny CSV called invoices.csv lives in this page's sandbox. It is six lines: a header row and five invoices. Everything below reads exactly this file.

data/invoices.csvinvoice_id,customer,amount,status 1001,Acme,250.00,paid 1002,Globex,540.50,open 1003,Initech,125.00,paid 1004,Umbrella,980.00,open 1005,Hooli,42.25,paid
Sandbox, not your computer. This file lives only in this page's memory (a "virtual filesystem"). The code here cannot reach your real files or any server — it is a safe place to practice the exact lines you will use later. When you load a real file, you do it in Colab or on your own machine (see the note at the bottom).

The notebook

Read it three ways, then call a function

Run the cells top to bottom. Each one reads data/invoices.csv a different way and shows you what came back. The last cells are yours to experiment in.

One more thing — the path

Every read above used the path "data/invoices.csv" with a forward slash. That is the portable shape: forward slashes work in Python on every operating system, including Windows. A Windows-style path with backslashes ("data\invoices.csv") can break, because in a Python string a backslash starts an escape sequence. When in doubt, use forward slashes, or build the path with pathlib: from pathlib import Path; Path("data") / "invoices.csv". The paths trainer covers this in full.

This page is a demo, not real file loading. The file here is baked into the sandbox so you can practice open(...) and pd.read_csv(...) safely. Loading a file that actually lives on your computer or your Google Drive happens in Colab or a local Python install — same lines, real file. That is where the Lab and Homework do their reading. The path gotcha above is exactly what bites you there, so it is worth getting comfortable with the forward-slash habit now.