About this question
Create a sample visual in power BI using Python script. Basic steps to run a Python script.
Create a sample visual in power BI using Python script. Basic steps to run a Python script.
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Python Expert
Answered on Jul 26, 2021
Follow the below steps:
1. Run Power BI and load the data source.
2. If Python Script does not exist, then to setup python script in Power BI visit below link,
3. Once Python is setup. Click on Python Script on the desktop window.
4. Python script visual is seen on the screen.
5. Go to Python script and select the fields that you want to use in visual.
6. Now install matplotlib in python using pip.
7. Then write code as below - to create a bar chart.
import matplotlib.pyplot as plt
plt.bar(dataset.Market,dataset.Sales)
plt.xlabel("Sales")
plt.ylabel("Profit")
plt.show()To create a Scatter chart using Python - use below code with different fields as required.
import matplotlib.pyplot as plt
plt.plot(dataset.Sales,dataset.Profit,'go')
plt.xlabel("Sales")
plt.ylabel("Profit")
plt.show()Another example of pair plot that is present on the top right side of the screen with multiple graphs is used to show the correlation of different fields.
import matplotlib.pyplot as plt
import seaborn as ssn
ssn.pairplot(dataset)
plt.show()In the above 2 Python scripts, within ' ' indicates the type of plot and color such as g,r indicates green and red color for the graph and o,- indicates scatter plot or dashed line chart and combining both you would get a dual axis chart.
Note: The Power BI Python integration requires the installation of two Python packages: Pandas. A software library for data manipulation and analysis. It offers data structures and operations for manipulating numerical tables and time series. Your imported data must be in a pandas data frame.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Python interview questions, answered
Guides, tips and career advice on Python from JanBask experts.
Python How to Become a Python Developer: A Step-by-Step Guide for Beginners
Discover how to become a Python Developer via a practical 7-step guide build projects, maintain clean code, practice daily, and…
Python PCEP Certification Guide: Entry-Level Python Programmer Certification
Explore this PCEP certification guide for insights on cost, exam format, passing score, application, training, and study tips.…
Python Top 50+ Python Projects ideas for Beginners to Advanced
Discover innovative Python project ideas, explore advanced Python projects, and find good Python projects for beginners and…
Python How To Comment Out Multiple Lines In Python Like A Pro
Commenting out code is a common practice among programmers. It allows you to temporarily disable parts of your code without…