Organize your workspace
You already have apython-for-ai workspace from earlier in the course. Open it in VS Code and add a dedicated project folder with this layout:
Create the data file
Insidesales-analysis/data/, create a file called sales.csv with the following content:
Copy and paste this data directly into a new file. Make sure the file extension is
.csv, not .txt — VS Code may try to add .txt if you’re not careful.Understanding file paths in your project
When your script runs, Python looks for files relative to the folder it’s running from. If you keep your script in thesales-analysis/ folder, these paths will work:
Create your first script
In thesales-analysis/ folder (not inside a subfolder), create analyzer.py:
Running your code
VS Code gives you two convenient ways to run Python code:Option 1: The Play button
- Open
analyzer.pyin VS Code - Click the ▶️ button in the top-right corner
- Output appears in the terminal below
Option 2: Interactive mode (recommended for learning)
- Open
analyzer.pyin VS Code - Place your cursor on any line (or select a block)
- Press Shift + Enter
- The code runs in an interactive window and you see results immediately
Keeping
analyzer.py at the top of your project folder — alongside data/ and output/ — means file paths stay simple and consistent whether you use the Play button or interactive mode.Best practices
- Keep data separate — Never mix your Python scripts and your data files in the same folder
- Use clear names —
data/for inputs,output/for results makes the project self-documenting - Put scripts at the project root — Your main script should sit at the same level as
data/andoutput/ - Test incrementally — Use Shift + Enter to run and verify each section as you write it
Python paths
Learn how Python finds your files and imports