Home / Blog

Python Visualizations in Power BI Service

William Tsu
Data Analyst
Experienced data analyst working with data visualization, cloud computing and ETL solutions.
January 16, 2020

What is a Power BI?

Power BI is a powerful business analytical tool than can retrieve data from one or more business operating systems and combine it in a repository. The repository may include a data warehouse, where large data is collected from varied sources within a company to provide meaningful management decisions. With this technology, any developing organization can monitor its operations more closely and able to get an instant response. Power BI has transformed the operation of the business in diverse ways. Interactive data visualization and discovering useful information have been introduced through business intelligence capabilities. Therefore, it helps in providing a simple interface for the end-users and arriving at better decisions. Power BI can help to deal with complex data dashboards and can view information more effectively than before. Through Power BI one can share, distribute and see Python visuals. This indeed increases the assistance for Python in the Power BI desktop.

Features and benefits of Microsoft Power BI

• One of the most reliable and fastest means to get an answer from the stored or used information in a computer is to ask a question using simple language. The Q&A function helps to explore your data and thereby create visuals. The Power BI service contains a dashboard, where a Q&A question box is displayed in the upper-left corner. Here you can type your question using the natural language.

• This business analytical tool i.e., Power BI is simple to use.

• Power BI offers a secure and reliable connection to your data sources available in the cloud or on-premises.

• Power BI requires minimal upfront cost and one can get started by accessing to free version.

• By upgrading to the Power BI Pro version, you can share the data visualizations with the respective colleagues in your enterprise.

What is Python?

Python is an object-oriented programming language, which contains data in the form of fields and code. Python is classified among the richest and interpreted language that executes instructions directly and freely, one line at a time. The Python programming language was devised in the late 1980s and it was the successor of ABC programming language.

Advantages of Python programming Language

• Simple and easy - the Python object-oriented language is simple to learn, comprehend and code when compared to any other programming language.

• IoT (Internet of Things) Opportunities - This language is a way to connect with the real world as it is embedded within the Internet of Things,

• Readable - Simple programming language is used hence it does not need curly braces to define blocks. This further results in easier readability

• Affordable - Python is cost-friendly, and therefore individuals, small companies or large organizations may not find it difficult to avail it.

Using Python Visuals in Power BI

We should install the Python is the operating system before we can start using the Python scripts in Power BI. Python is used for importing data, data transformation, and data visualization. One needs to use the python scripts to prepare the dataset. Dataset is the collection of related data that relate to a particular subject. After using the Python scripts, apply sophisticated analytics or machine learning in the Power BI. The inclusion of Python visuals in the Power BI report is done by selecting the Python visual symbol from the visualizations sheet. This is one of the substantial things that Microsoft has done. Here the user gets the ability to utilize the visual libraries available in python. Other than the Python visualization, one can also make effective use of the machine learning packages. To improve your data visualization skills, you must incorporate the latest version of Power BI. This version will have the Python integration in their features option, and thereby click on enabling them.

The fields from your data set can be incorporated into the value sheet depicting the Python visual. When the report gets published in the Power BI workplace, an auto-refresh option pops in and you can view the latest ones in the report. The visuals can also get updated with cross-filtering within the report and this can be a powerful combination too.

Security and execution of Python scripts

The execution of Python scripts in the reports is done by the Power BI system. This is to guarantee that the collected data and the administration of the Power BI are not likely to be susceptible to any assaults. Python script execution on the Power BI has got size restrictions and the execution time is restricted to 300 seconds.


Creating Python visuals in Power BI reports

Click the Python visual icon and thereby you can add a Python visual on to your Power BI, which adds a placeholder Python script to the report. You can also add the required fields from the dataset, which creates a Data Frame. Using libraries like Matplotlib and Seaborn custom scripts can be written to create the visuals. Power BI functionalities such as slicers, filters are used on top of the python visuals to make the appropriate selections.

Types of Visualizations

Before choosing the right visualizations, the construction of some exploratory data analysis is important. After knowing the exact data, the data types and other useful information, selecting the appropriate visual images will be comparatively easier. An enormous number of visualization packages are available in Python. Matplotlib is one of the most famous packages. Matplotlib can work with various operating systems and graphics backend. It possesses high-quality images with the finest quality and thereby giving accurate results. It can be effectively used in Python scripts and other web application servers. There are several types of visualizations and some of them are as follows: line plot, histogram, scatter plot, bar chart, pie chart, and box plot.

• Line Plot: It displays the collected information in a sequence of data points which is termed as "Markers". These plotted points are connected by straight lines. Line plots are often used to envision a trend in data over different intervals of time commonly known as time series. To make a line plot with Matplotlib, we need to apply a Python function i.e., plt.plot(). Now to display the plot, another Python function is required i.e.,

• Scatter Plot: All individual data points are exhibited in this type of plot without connected lines. Each data point has got two values; the x-axis value and the y-axis value. Scatter plots are mainly used to represent trends and correlation. To make a scatter plot with Matplotlib, we use the plt.scatter() function.

• Histogram: Histogram represents the distribution of numeric data. For creating a histogram, we need to apportion the entire range of values into a sequence of intervals. These intervals are also known as bins. To make a histogram using Matplotlib, we need to apply the plt.hist() function.

• Box Plot : Box Plots are also known as box-and-whisker plot. In box Plot values are distributed based on five number summary such as : minimum, first, quartile, median, third quartile and maximum.

» The minimum and maximum values are the min and mix values collected from our data.

» The median is the value that is used for separating the upper half of a data from the lower half.

» The first quartile is the data values to the left of the median. For Example, say we have numbers 1,2,3,4,6,7,8,5,9. The first quartile will be the median from 1,2,3.

» The third quartile is the data values to the right of the median. Considering the above example; the third quartile will be 8,5,9.

Now to create a box plot with Matplotlib we need to use the plt.boxplot() function.

• Bar chart: bar chart represents a set of data with rectangular bars. The height and breadth of each bar corresponds to the value it represents. Bar charts can be useful when a comparison is to be made on a given numeric value and different categories. To design a Bar chart using Matplotlib we need to use the function.

• Pie chart: is a circular plot that is apportioned into various slices depicting the numerical portion. Pie chart is the most common type of Python visualization that is used in the business world. Pie charts can be created in Matplotlib using the function key plt.pie()