Aggregate SQL Query Results with Pandas and Export to Excel
Beginner Mode

Start your terminal to use beginner mode.

Sign in to watch the walkthrough video

Sign In

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:

  1. Connects to the SQLite database at /home/interview/orders.db
  2. Executes a SQL query to fetch customer and order data (join the tables)
  3. Loads the results into a pandas DataFrame
  4. Calculates total order value per customer using pandas
  5. Saves the results to /home/interview/customer_totals.xlsx with 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.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →