0% found this document useful (0 votes)
109 views

2.6 Python in Power BI: 2.6.1. Configuration

The document discusses how to configure Python and R in Power BI. It describes downloading and installing Python and R and verifying the installations. It also explains how to import data into Power BI using Python and R scripts, clean data with Python scripts, and create visualizations by writing Python and R scripts within Power BI.

Uploaded by

george
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views

2.6 Python in Power BI: 2.6.1. Configuration

The document discusses how to configure Python and R in Power BI. It describes downloading and installing Python and R and verifying the installations. It also explains how to import data into Power BI using Python and R scripts, clean data with Python scripts, and create visualizations by writing Python and R scripts within Power BI.

Uploaded by

george
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

2.

6 Python in Power BI
2.6.1. Configuration
• Install Python on your local or virtual machine:
https://www.python.org/downloads/

• Install required Python:


Open Command Prompt, input the following commands to install packages if you use Python
version 3.7:
py -m pip install pandas
py -m pip install matplotlib
py -m pip install numpy
py -m pip install seaborn
2.6 Python in Power BI
2.6.1. Configuration
Pandas is used for the interaction with data in tabular format;
Matplotlib is the standard plotting library;
Numpy is used to deal with arrays and matrix;
Seaborn is used to have nice looking charts.

Use the following command to upgrade pip if needed.


python -m pip install --upgrade pip
2.6 Python in Power BI
2.6.1. Configuration
• When there is no Python visual
on the right visualizations pane,
try the following steps:
File – Options and settings – Options
– Preview features – Python support
Restart Power BI to get Python
Running.
2.6 Python in Power BI
2.6.1. Configuration
• Check if Python is installed
by clicking on File –
Options and settings –
Options – Python scripting.
If it’s installed, then it will
show a path where it is
installed. 
2.6 Python in Power BI
2.6.2. Import the dataset into Power BI
• Go to File – Get data –
Excel/CSV/Access to connect to
the dataset.
• You can also import your data by
running a Python script directly.
1) Go to File – Get data – All –
Python script.
2) Copy paste the following script
into the Python script box.
Remember to adapt the path to
your local file location.
2.6 Python in Power BI
2.6.2. Import the dataset into Power BI
Note: If you get error when you are
trying to use this method to import
external file into Power BI, try the
following command:

py -m pip install xlrd


2.6 Python in Power BI
2.6.2. Import the dataset into Power BI
• Or you can manually import a very small amount of data
2.6 Python in Power BI
2.6.3. Data cleaning and Data integration using Python script
1) In Power BI, click Home – Edit Queries from Home tab.
2) Then in the Power Query Editor, click Transform – Run Python script.
2.6 Python in Power BI
2.6.3. Data cleaning and Data integration using Python script
2.6 Python in Power BI
2.6.3. Data cleaning and Data integration using Python script
Clicking on OK in the Run Python Script window, and this will create a table.
2.6 Python in Power BI
2.6.3. Data cleaning and Data integration using Python script
This demo is used to get rid of the rows with null data in a specific column if
needed.
2.6 Python in Power BI
2.6.3. Data cleaning and Data integration using Python script
This demo is used to fill the NA’s with the mean value if needed.
2.6 Python in Power BI
2.6.3. Data cleaning and Data integration using Python script
Note: If Query editor displays a warning about data privacy, try to set to public for all
data sources.
2.6 Python in Power BI
2.6.4. Create Python visuals
1) Select the Python visual icon in the Visualization pane and select Enable.
2.6 Python in Power BI
2.6.4. Create Python visuals
2) Click the Run Script Button in the Visualization pane and select Enable.
2.6 Python in Power BI
2.6.4. Create Python visuals
3) Drag fields to the Values
section.
Note:
a) Your Python script can only
use fields added to the Values
section.
b) Duplicate rows will be
removed from the data. You
can remove the row “#dataset
= dataset.drop_duplicates()” if
you need all the rows of your
datasets.
2.6 Python in Power BI
2.6.4. Create Python visuals
4) Add Python code and use the selected data to create plots.
We use the following code to create a bar plot. You can create scatter/line by change
parameter “kind”.
2.7 R in Power BI
2.7.1. Configuration
• Install R on your local or virtual machine:
https://www.r-project.org/

• When there is no R visual on the right visualizations panel, try the following steps:
File – Options and settings – Options – Preview features – R support;
Restart Power BI to get R Running.
2.7 R in Power BI
2.7.1. Configuration
• Check if R is installed by
clicking on File – Options
and settings – Options – R
scripting. If it’s installed,
then it will show a path
where it is installed. 
2.7 R in Power BI
2.7.2. Import the dataset into Power BI
Same methods as using Python script to import datasets into Power BI, we can import datasets
directly or using R script or manually.
2.7 R in Power BI
2.7.3. Create R visuals
1) Select the R visual icon in the Visualization pane and select Enable.
2.7 R in Power BI
2.7.3. Create R visuals
2) Click the Run Script Button in the Visualization pane and select Enable.
2.7 R in Power BI
2.7.3. Create R visuals
3) Drag fields to the Values
section.
Note:
a) Your R script can only use
fields added to the Values
section.
b) Duplicate rows will be
removed from the data. You
can remove the row “dataset
-> unique(dataset).” if you
need all the rows of your
datasets.
2.7 R in Power BI
2.7.3. Create R visuals
4) Add R code and use the selected data to create plots.
We use the following code to create a line plot.
References:
1. https://docs.microsoft.com/en-us/power-bi/desktop-python-scripts
2. https://docs.microsoft.com/en-us/power-bi/desktop-python-visuals
3. https://docs.microsoft.com/en-us/power-bi/desktop-python-ide
4. https://docs.microsoft.com/en-us/power-bi/desktop-r-scripts
5. https://docs.microsoft.com/en-us/power-bi/desktop-r-visuals
6. https://docs.microsoft.com/en-us/power-bi/desktop-r-ide

You might also like