Power BI & Python Integration
Introduction
This guide is designed to walk you through the process of integrating Python into Power BI, a synergy that unlocks a new realm of possibilities for data analysis and business intelligence.
Prerequisites
-
Install Python: Ensure python is installed on your computer.
-
Install Power BI Desktop: If you haven’t already, install Power BI desktop from the Microsoft Store.
Step-by-Step Guide
Setting Up Python in Power BI
-
Open Power BI Desktop.
-
Go to Options: In the top menu, click on
File
thenOptions and settings
and selectOptions
- Python Scripting Settings: In the
Options
window, navigate to thePython scripting
section. Here, you can specify the Python home directory and the IDE to be used.
Using Python in Power BI
Get and Model Data with Python
- Click Home, then
Get Data
and selectPython script
.
- Enter your python script to retrieve and model data. For example, you could use pandas to read CSV file and import relevant machine learning libraries to create a predictive model.
- Once the script is executed, you can select the Data Frame you want load to the Power BI model. Once selected, click
Load
to finalise orTransform Data
if you want to transform the data further using Power Query.
Python Visuals
- In the report view, select
Python visual
icon in theVisualisations
pane.
- Add the data fields you want to include in your Python script.
- A Python script editor will open at the bottom where you can write your script to create a visual. Libraries like matplotlib and seaborn can be used here.
-
Once you added your python script, click the play button in the top right-hand corner and your visual will render.
Useful Resources
-
Power BI Documentation: Power BI documentation - Power BI | Microsoft Learn
-
Python Documentation: Python 3.12.1 Documentation