Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Translation Challenge: SQL vs Pandas

Overview

This project demonstrates how to solve the same data analysis problems using both SQL and pandas. A sales dataset is loaded into a SQLite database and a pandas DataFrame, allowing each solution to be compared side by side. The script practices data aggregation, grouping, filtering, and calculating metrics using two common data analysis approaches.

Features

  • Loads sales data into a pandas DataFrame.
  • Creates and populates a SQLite database using sqlite3.
  • Uses SQL queries to analyze sales information.
  • Uses pandas operations to perform equivalent analysis.
  • Demonstrates how SQL and pandas can produce the same results using different syntax.
  • Includes a bonus example using pd.read_sql() to return SQL query results as a pandas DataFrame.

Requirements

Install the required dependency:

pip install pandas

Python libraries used:

  • sqlite3 — creates and interacts with the SQLite database.
  • pandas — provides DataFrame creation and data analysis tools.

Dataset

The script uses a provided sales dataset containing:

  • product
  • category
  • unit_price
  • quantity
  • quarter

File Structure

translation_challenge.py
README.md
sales.db

Running the Script

Run the program with:

python translation_challenge.py

The script will:

  1. Create a pandas DataFrame from the sales dataset.
  2. Create a SQLite database named sales.db.
  3. Load the DataFrame into the SQLite sales table.
  4. Execute SQL and pandas solutions for each analysis question.
  5. Display the results in the terminal.

Bonus

The script demonstrates pd.read_sql() by executing a SQL query and returning the results directly as a pandas DataFrame. This shows how SQL queries can integrate with pandas workflows for additional analysis.

Learning Goals

This project builds familiarity with:

  • Translating SQL queries into pandas operations.
  • Using aggregation functions such as SUM() and AVG().
  • Grouping and filtering data.
  • Working with SQLite databases.
  • Comparing relational database workflows with DataFrame-based analysis.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages