# analyze_grades.py
# Our first UV-managed project!
import pandas as pd
import numpy as np
def create_sample_data():
"""Create sample student grades data"""
students = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve']
data = {
'Student': students,
'Math': np.random.randint(70, 100, 5),
'Science': np.random.randint(70, 100, 5),
'English': np.random.randint(70, 100, 5),
'History': np.random.randint(70, 100, 5)
}
return pd.DataFrame(data)
# Create and display the data
df = create_sample_data()
print("๐ Student Grades:")
print(df)
# Calculate average for each student
df['Average'] = df[['Math', 'Science', 'English', 'History']].mean(axis=1)
print("\n๐ With Averages:")
print(df)
# Find the top student
top_student = df.loc[df['Average'].idxmax()]
print(f"\n๐ Top Student: {top_student['Student']} with {top_student['Average']:.2f} average!")Chapter 1.2: Installing UV & Creating Your First Project
Get UV Running and Build a Data Analysis Project
๐ PROJECT 1.2 | Difficulty: Intermediate | Time: 15 minutes
๐ Complexity Level: Intermediate โญโญ
Hands-on installation and project setup. Youโll learn terminal commands and project structureโessential skills for any developer!
๐ป Interactive Options:
- ๐ Open in JupyterLite - Full Jupyter environment in your browser
- ๐ฅ Download Notebook - For use in local Jupyter or Google Colab
- ๐ก Note: Installing UV requires a terminal, so weโll show examples but youโll run this locally!
Special Note: This project is designed for students who have completed the first chapter of CS Quests and are familiar with Python basics. If youโre new to programming, consider starting with the earlier lessons before diving into this project.
Another Special Note: This project requires a local Python environment for full functionality. While we provide examples and code snippets here, some features may not run directly in the browser. For the best experience, consider setting up the project on your own computer.
๐ Installation: Getting UV on Your Computer
UV works on macOS, Linux, and Windows. Letโs get it installed!
Step 1: Install UV
Open your terminal and run:
curl -LsSf https://astral.sh/uv/install.sh | shAfter installation, restart your terminal or run:
source $HOME/.cargo/envOpen PowerShell and run:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"Step 2: Verify Installation
Check that UV is installed correctly:
uv --versionYou should see something like: uv 0.1.x
โ Success! If you see a version number, UV is installed and ready to use!
๐๏ธ Creating Your First Project
Now letโs create a data analysis project. Weโll analyze student grades and create visualizations!
Initialize a New Project
# Create a new directory and navigate into it
mkdir student-grades-analyzer
cd student-grades-analyzer
# Initialize UV project
uv initThis creates a basic project structure:
student-grades-analyzer/
โโโ pyproject.toml # Project configuration
โโโ README.md # Project description
โโโ .python-version # Python version lock
๐ Whatโs pyproject.toml?
This is your projectโs configuration file. It tells UV:
- What your project is called
- Which Python version to use
- Which packages your project depends on
Think of it as your projectโs ID card!
๐ฆ Adding Dependencies
Now letโs add the packages we need for data analysis:
# Add pandas for data manipulation
uv add pandas
# Add matplotlib for creating charts
uv add matplotlib
# Add numpy for numerical operations
uv add numpyUV will: 1. โก Download and install each package (super fast!) 2. ๐ Create a uv.lock file to freeze exact versions 3. ๐ Update pyproject.toml with your dependencies
โฑ๏ธ Speed Comparison:
Traditional pip might take 1-2 minutes to install these packages.
UV does it in 5-10 seconds! ๐
๐ Understanding the Project Structure
After adding dependencies, your project looks like this:
student-grades-analyzer/
โโโ .venv/ # Virtual environment (UV creates this)
โโโ pyproject.toml # Project config with dependencies
โโโ uv.lock # Locked versions for reproducibility
โโโ README.md
โโโ .python-version
๐ฏ Letโs Write Our First Script
Create a file called analyze_grades.py:
โถ๏ธ Running Your Project
To run your script with UV:
# UV automatically uses the right Python and packages!
uv run python analyze_grades.pyNo need to activate a virtual environmentโUV handles it automatically!
๐ก Pro Tip: The uv run command automatically uses your projectโs virtual environment. No more source venv/bin/activate needed!
๐ Common UV Commands
Here are the most useful UV commands:
# Initialize a new project
uv init
# Add a package
uv add package-name
# Remove a package
uv remove package-name
# Run a script
uv run python script.py
# Show installed packages
uv pip list
# Update all packages
uv lock --upgrade๐ฎ Try It Yourself!
- Create a new UV project called
my-data-project - Add pandas and matplotlib
- Create a simple script that prints โHello from UV!โ
- Run it with
uv run python your_script.py
๐ Challenge:
Modify the analyze_grades.py script to:
- Add a โGrade Letterโ column (A for 90+, B for 80+, etc.)
- Calculate class averages per subject
- Find which subject has the highest class average
๐ Whatโs Next?
Now that you have UV set up and a working project, in the next slide weโll:
- Dive deeper into pandas for data manipulation
- Load data from files (CSV, Excel)
- Clean and transform real-world data