Create Power BI visuals using Python

  1. Home
  2. Create Power BI visuals using Python

We shall learn to create Power BI visuals using Python in this tutorial. So before you begin, you must learn that you can use Python to visualize your data with Power BI Desktop. But, one of the prerequisites is that you need to work through the Run Python scripts in Power BI Desktop tutorial using the following Python script:

import pandas as pd 
df = pd.DataFrame({ 
    'Fname':['Harry','Sally','Paul','Abe','June','Mike','Tom'], 
    'Age':[21,34,42,18,24,80,22], 
    'Weight': [180, 130, 200, 140, 176, 142, 210], 
    'Gender':['M','F','M','M','F','M','M'], 
    'State':['Washington','Oregon','California','Washington','Nevada','Texas','Nevada'],
    'Children':[4,1,2,3,0,2,0],
    'Pets':[3,2,2,5,0,1,5] 
}) 
print (df) 

Steps to Create Python visuals in Power BI Desktop

  • Firstly, select the Python visual icon in the Visualizations pane.
  • Secondly, in the Enable script visuals dialog box that appears, select Enable.
  • Then when you add a Python visual to a report, Power BI Desktop takes the following actions – Firstly, a placeholder Python visual image appears on the report canvas. Also, The Python script editor appears along the bottom of the center pane.
  • Next, drag the AgeChildrenFnameGenderPetsState, and Weight fields to the Values section where it says Add data fields here.
  • Now you can use the data you selected to create a plot. Then, as you select or remove fields, supporting code in the Python script editor is automatically generated or removed.
  • With the dataframe automatically generated by the fields you selected, you’re ready to write a Python script that results in plotting to the Python default device. When the script is complete, select Run from the Python script editor title bar.
  • Then, with the dataframe automatically generated by the fields you selected, you will be ready to write a Python script that results in plotting to the Python default device.
  • Lastly, when the script is complete, select Run from the Python script editor title bar.

Limitations of using Python visuals in Power BI Desktop

  • The first limitation is Data size Constraints. The data utilized by the Python visual for plotting is restricted to 150,000 rows. Therefore, if more than 150,000 rows are selected, then only the top 150,000 rows are used and a message is displayed on the image. In addition, the input data has a limit of 250 MB.
  • Second limitation Resolution. The second limitation is that all Python visuals are displayed at 72 DPI.
  • Thirdly, calculation time limitation. Then, if a Python visual calculation exceeds five minutes the execution times out which results in an error.
  • Fourth, is Relationships limitation. As with other Power BI Desktop visuals, if data fields from different tables with no defined relationship between them are selected, an error occurs.
  • Then, Python visuals will be refreshed only upon data updates, filtering, and highlighting. Nonetheless, the image itself isn’t interactive and can’t be the source of cross-filtering.
  • Next, Python visuals react to highlighting other visuals, but you can’t click on elements in the Python visual to cross filter other elements.
  • Further, only plots that are plotted to the Python default display device are displayed correctly on the canvas.
  • Lastly, python visuals do not support renaming input columns. Columns will be referred to by their original name during script execution.

For more details visit: Create Power BI visuals by using Python

Microsoft Exam DA-100 Free Practice Test
Menu