CSV Files
π¨π Technique Card: Working with CSV Files (practical)
Big Idea: A CSV file is a way to store data in plain text β it stands for Comma-Separated Values.
Useful for: Saving data from surveys or projects, using data in Scratch, Python, or spreadsheets.
π§ Whatβs a CSV?
A CSV is just a list of data stored in a text file, where each line is a row and each comma separates columns.
Hereβs what a simple CSV might look like:
Name,Travel Type
Alice,Walk
Ben,Bike
Cleo,Car
Dan,Walk
π Each row is like one row in a spreadsheet. The commas act like the borders between columns.
β Why Use CSV Files?
- β They work with lots of programs (Excel, Scratch extensions, Python, Google Sheets)
- β Easy to share and upload
- β Super simple to create by hand or from a spreadsheet
- β Great for storing survey results, project data, and changing values in code
π§ͺ How to Make a CSV File
βοΈ Method 1: With a Text Editor (like Notepad)
- Open Notepad (or any plain text editor).
- Type your data like this:
Food,Distance (km)
Apples,120
Bananas,6000
Carrots,50
- Save it as:
food_miles.csv
π Make sure it ends in.csv
, and not.txt
.
π Method 2: With Excel (or Google Sheets)
- Type your data into the spreadsheet like normal.
- Go to File β Save As (or Download).
- Choose CSV (Comma delimited) (.csv) as the file type.
- Save!
π Now your data is in a plain text format that other programs can understand.
π‘ Top Tips
- Donβt use commas inside your data unless you really have to (it can confuse the file!)
- Always check the first line β itβs the header and tells what each column means.
- You can open CSV files in Excel, Google Sheets, Python, and some Scratch extensions (like the Data Importer).
π Try This!
Make a CSV with:
Name,How they get to school
Max,Walk
Tia,Bus
Alex,Bike
Open it in a spreadsheet and see the data appear in separate columns!
Then try changing the file in the text editor and reloading it.