Python Environment Setup Complete! šŸŽ‰

Your Quarto site now supports both R and Python code execution using uv for fast Python package management.

What Was Set Up

1. Python Environment

  • āœ… Virtual environment created with uv venv
  • āœ… All data science packages installed:
    • Core: pandas, numpy, matplotlib, seaborn, scipy
    • ML/Stats: statsmodels, scikit-learn
    • Database: sqlalchemy, pyodbc, psycopg2-binary
    • Geospatial: folium, geopandas
    • Visualization: plotly, altair
    • Jupyter: jupyter, ipykernel
    • Utilities: python-dotenv, requests

2. Quarto Configuration

  • āœ… Updated _quarto.yml to support multiple engines
  • āœ… Python code execution verified and working
  • āœ… Both R and Python can be used in the same site

3. Helper Scripts

  • āœ… setup_python.py - Automated setup and testing
  • āœ… with_python_env.sh - Convenience script for running commands
  • āœ… python_utils.py - Python equivalents of R functions

Quick Start

Render Your Site

# Option 1: Activate environment manually
source .venv/bin/activate && quarto render

# Option 2: Use convenience script
./with_python_env.sh quarto render

Preview Your Site

./with_python_env.sh quarto preview

Using Python in Posts

Create Python code blocks in your .qmd files:

#| echo: true
#| eval: true
import pandas as pd
import matplotlib.pyplot as plt

# Your Python analysis code
data = pd.read_csv('your_data.csv')
data.plot()
plt.show()

Python Equivalents of Your R Functions

The python_utils.py file provides Python versions of your R analysis functions:

  • custom_summary() - Comprehensive statistics
  • extract_datetime_features() - Date/time processing
  • create_response_time_plots() - Analysis visualizations
  • create_geographic_map() - Interactive mapping with Folium
  • load_sql_data() - Database connectivity

Example Usage

from python_utils import custom_summary, create_geographic_map
import pandas as pd

# Load your cardiac arrest data
df = pd.read_csv('cardiac_arrests_cy.csv')

# Get comprehensive statistics (equivalent to your R function)
stats = custom_summary(df['call_entry_time'])
print(stats)

# Create interactive map (equivalent to your R leaflet maps)
map_obj = create_geographic_map(df)
map_obj.save('cardiac_arrests_map.html')

Files Added/Modified

  • _quarto.yml - Added Python engine support
  • .venv/ - Python virtual environment
  • python_utils.py - Python utility functions
  • setup_python.py - Setup automation
  • with_python_env.sh - Convenience script
  • requirements.txt - Package dependencies (backup)
  • PYTHON_README.md - Detailed documentation

Your site now has the flexibility to use either R or Python (or both!) for your data science content. The Python environment provides equivalent functionality to your R workflow with modern, fast package management via uv.