Skip to content

Commit 484c33f

Browse files
committed
Power BI: Initial commit
1 parent c147bde commit 484c33f

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

power-bi-python/01_ingest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sqlite3
2+
3+
import pandas as pd
4+
5+
with sqlite3.connect(r"C:\Users\User\Desktop\car_sales.db") as connection:
6+
df = pd.read_sql_query("SELECT * FROM sales", connection)
7+
8+
cars = df[
9+
[
10+
"vin",
11+
"car",
12+
"mileage",
13+
"license",
14+
"color",
15+
"purchase_date",
16+
"purchase_price",
17+
"investment",
18+
]
19+
]
20+
customers = df[["vin", "customer"]]
21+
sales = df[["vin", "sale_price", "sale_date"]]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 'dataset' holds the input data for this script
2+
dataset = dataset.assign(
3+
full_name=dataset["customer"].str.extract(r"([^<]+)"),
4+
email=dataset["customer"].str.extract(r"<([^>]+)>"),
5+
).drop(columns=["customer"])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 'dataset' holds the input data for this script
2+
dataset[["first_name", "last_name"]] = dataset["full_name"].str.split(
3+
n=1, expand=True
4+
)
5+
dataset.drop(columns=["full_name"], inplace=True)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
2+
3+
# dataset = pandas.DataFrame(color, vin)
4+
# dataset = dataset.drop_duplicates()
5+
6+
# Paste or type your script code here:
7+
import matplotlib.pyplot as plt
8+
9+
plt.style.use("seaborn")
10+
11+
series = dataset[dataset["color"] != ""]["color"].value_counts()
12+
series.plot(kind="bar", color=series.index, edgecolor="black")
13+
14+
plt.show()

power-bi-python/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Microsoft Power BI and Python: Two Superpowers Combined
2+
3+
These are supplementing materials for the Real Python [tutorial](https://realpython.com/power-bi-python/) on using Python in Microsoft Power BI Desktop, which include:
4+
5+
- SQLite database with a single `sales` table (fake used car sales dataset)
6+
- Python scripts used in the tutorial
7+
- The resulting Power BI Desktop report

power-bi-python/car_sales.db

148 KB
Binary file not shown.

power-bi-python/report.pbix

198 KB
Binary file not shown.

0 commit comments

Comments
 (0)