92. Aggregate SQL Query Results with Pandas and Export to Excel
Beginner Mode
Start your terminal to use beginner mode.
Scenario
A SQLite database contains customer and order data across multiple tables. You need to analyze total order values per customer and export the results to Excel.
Task
Write a Python script at /home/interview/analyze_orders.py that:
- Connects to the SQLite database at
/home/interview/orders.db - Executes a SQL query to fetch customer and order data (join the tables)
- Loads the results into a pandas DataFrame
- Calculates total order value per customer using pandas
- Saves the results to
/home/interview/customer_totals.xlsxwith columns:customer_id,customer_name,total_order_value
Note: pandas and openpyxl are already installed. The database contains customers and orders tables.
Database Schema
customers table:
- id (INTEGER)
- first_name (TEXT)
- last_name (TEXT)
- email (TEXT)
orders table:
- id (INTEGER)
- customer_id (INTEGER)
- order_date (TEXT)
- order_amount (REAL)
Terminal requires a larger screen
Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.
Linux Terminal Environment
Write and execute your solution in the terminal below.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
Meta
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
OpenAI
Hulu
Uber
X
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla