Part One
What Is a CSV File?
CSV stands for comma-separated values. It is one of the simplest ways to store table data in a file. Each line is a row. Each comma separates one column from the next.
When you work with pandas on real projects, a very common workflow is: read a CSV → analyse the data → write a new CSV. That is how you move data between spreadsheets, scripts, and reports.
| Path | What It Means |
|---|---|
"prices.csv" |
A file named prices.csv in the same folder as your script or notebook. |
"data/prices.csv" |
A file inside a subfolder called data. |
"C:/Users/Ana/data/prices.csv" or "/Users/ana/data/prices.csv" |
An absolute path: the full location of the file on your computer. |
"prices.csv".
Part Two
Reading a CSV with pd.read_csv()
pd.read_csv("prices.csv") tells pandas: “open the file called prices.csv and turn it into a DataFrame.” In this playground, we create the file first so the example can run. On your own computer, the file would usually already exist.
The result is a normal DataFrame. Once the file is loaded, you can use everything you already know: .head(), filtering, sorting, groupby(), new columns, and so on.
Part Three
Writing a CSV with .to_csv()
To save a DataFrame to a CSV file, use .to_csv("filename.csv"). The filename is the path where you want the file to be written.
The option index=False is important. Without it, pandas also writes the row numbers as an extra first column. Most of the time, that is not what you want in a CSV you plan to share or reopen later.
index=False unless you deliberately want the row numbers saved into the CSV.
Part Four
A Full CSV Workflow
Here is the complete pattern you will use in real work: load a CSV, analyse it, then save the result as a new CSV.
Notice the flow: prices.csv comes in, pandas creates a summary table, and then that summary is written to category_summary.csv. This is how you build outputs that editors, classmates, or other scripts can reuse.
Part Five
Your Turn — Save and Reload Your Own Data
Create a small price table of your own, save it to a CSV, read it back in, and then save a filtered version. Try to produce two files:
my_prices.csv— your full datasetbudget_items.csv— only items cheaper than your chosen threshold
Chapter Navigation
Move between chapters.