Use SQL inside Python to pull sales info (like total quantity sold, total revenue) and visualize it.
- Python (sqlite3, pandas, matplotlib)
- SQLite (built into Python, no setup required)
- Created a SQLite database
sales_data.db
with asales
table. - Inserted sample sales records (products, quantity, price).
- Ran SQL queries inside Python using
sqlite3
. - Loaded results into pandas DataFrame.
- Printed the sales summary.
- Visualized revenue by product using matplotlib.
Sales Summary:
Product | Total Quantity | Revenue |
---|---|---|
Laptop | 8 | 474000 |
Mobile | 18 | 274000 |
Tablet | 10 | 206000 |
Headphones | 19 | 43500 |
Bar Chart:
Revenue by Product (saved as sales_chart.png
)
- How did you connect Python to a database?
- What SQL query did you run?
- What does GROUP BY do?
- How did you calculate revenue?
- How did you visualize the result?
- What does pandas do in your code?
- What’s the benefit of using SQL inside Python?
✅ Submission ready!