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.
- 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.
Install the required dependency:
pip install pandasPython libraries used:
sqlite3— creates and interacts with the SQLite database.pandas— provides DataFrame creation and data analysis tools.
The script uses a provided sales dataset containing:
productcategoryunit_pricequantityquarter
translation_challenge.py
README.md
sales.db
Run the program with:
python translation_challenge.pyThe script will:
- Create a pandas DataFrame from the sales dataset.
- Create a SQLite database named
sales.db. - Load the DataFrame into the SQLite
salestable. - Execute SQL and pandas solutions for each analysis question.
- Display the results in the terminal.
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.
This project builds familiarity with:
- Translating SQL queries into pandas operations.
- Using aggregation functions such as
SUM()andAVG(). - Grouping and filtering data.
- Working with SQLite databases.
- Comparing relational database workflows with DataFrame-based analysis.