Posted in Analyatics, BI, python

Python in Power B I.

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 visual in Power BI

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.

Making matrix and importing package

To check all packages:

Setting Environment:
Steps.

  1. Conda activate env_new == 3.9
  2. pip install pandas
  3. pip install seaborn
Setting the python environment

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.
Options in power BI – Python scripting

3. Get data

Data option

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()

Final output!

Stay tuned for more exciting stuff!!

2 thoughts on “Python in Power B I.

Leave a comment