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.ymlto 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 renderPreview Your Site
./with_python_env.sh quarto previewUsing 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 statisticsextract_datetime_features()- Date/time processing
create_response_time_plots()- Analysis visualizationscreate_geographic_map()- Interactive mapping with Foliumload_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 environmentpython_utils.py- Python utility functionssetup_python.py- Setup automationwith_python_env.sh- Convenience scriptrequirements.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.