Python in Power B I.

The Data Insights
3 min readMar 19, 2022

Python in PBI is used to enhance the report. This blog will guide you to understand how to use the Python visual in PBI.

Python is a programing language which is used to create visualizations in power bi and Anaconda is free and open source distribution of R and Python.

Steps to begin the python scripting for power B I.

  • Install Anaconda.
    Can use this link for reference: Installation — Anaconda documentation
    Note: Check the OS before installation.
  • Launch Jupiter/ Spyder — where the programming commands can be run.
  • Open Jupiter — from system.
  • Create a new note book.
  • Start scripting.

Note: One can start from basic python language to understand the scripting in detail.

To check all packages:

Setting Environment:
Steps.

  1. Conda activate env_new == 3.9
  2. pip install pandas
  3. pip install seaborn

Importing packages, extracting data and plotting graph.

  • Importing Package

#importing the package
import pandas as pd
import matplotlib.pyplot as plt

import seaborn as sns
import warnings as wa
wa.filterwarnings('ignore')

  • Load the Data
  • #load the data
    data = pd.read_csv("C:/Users/Admin/OneDrive - Depth Consulting Services Pvt. Ltd/Desktop/Dummy data.csv")
    data
  • Data Types:
  • Plotting graphs in python:

plt.style.use("ggplot")
plt.figure(figsize=(8,5))
data.groupby('Production')['Profit in cr'].sum().plot(kind = 'barh')

  • SNS Plot:

plt.figure(figsize=(8,5))
sns.distplot(data["satisfaction_level"]);

  • Box Plot:

plt.figure(figsize=(8,5))
sns.boxplot(x = data["satisfaction_level"], y = data["Departments"]);

Using these visuals in Power B I

  1. Open PBI Desktop
  2. File -> Options -> Python Scripting -> set the python directory path.

3. Get data

4. Select the python visual and run the script.
Script:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use("ggplot")
plt.figure(figsize=(8,5))
dataset.groupby('Production')['Profit in cr'].sum().plot(kind = 'barh')
plt.show()

Stay tuned for more exciting stuff!!

Find me on Wordpress and Spotify and also on Radio Public!

--

--