Integrating Python in Power BI With An Example Of Data Wrangling & Data Visualization

 


With a mix of Power BI & Excel's versatility and coding experience, You can easily wrangle any kind of data and get the most out of it.

Let's see how we can use python in two processes (Data Wrangling & Data Visualization) inside Power BI

  • Make sure that anaconda and python3 installed on your pc.


  1. Our Data set

The dataset I'm using for this article is a Kaggle dataset that I've recently worked on you can check it out here
what we are going to do is to transform some of my work in this notebook to power bi.


  1. 2. Data wrangling

The data wrangling process in power bi is based inside the query editor

After loading your data click on the transform tab then run a python script
then you will need to import your libraries and run your code
for me, the dataset only needed to replace some values and to get the date and time 
for more information check out my Kaggle notebook

You will get this after running your code
this is the new dataset after running your code 
so all you have to do is to remove the named column as we don't need it 
and expand the value column which holds our data

Here's our clean data ready to be loaded

  1. 3. Data Visualization 
Now let's get to the fun part, From my notebook I've selected two visuals that I wanted to show in my power bi file
1- select the python visual
2- load your data into it
3- write your code
4- run

 But here are some important notes you should know:
  • Don't forget to import your libraries (numpy as np, pandas as pd, matplotlib.pyplot as plt, seaborn as sb....etc)
  • Your dataset has its name now as 'dataset', not 'df' or else. you will have to change it if you want or keep it as it is.
  • Don't forget plt.show() at the end this is our magic word

Here's another one


Now you are good to go.
Regards.

Comments

Popular posts from this blog

REDUCE Your Measures With Calculation Groups In Power BI

شرح الأداة الرائعة Tabular Editor للـ Power BI