In our previous post, we installed and set up Python for use in Power BI. In this post, we will run a Python script and use that as a datasource in Power BI.
In Power BI Desktop, select Get Data, then More:
Select Python script and Connect:
This will open a Python script. Paste in the code from the previous example.
import pandas as pd data = [['Alex',10],['Bob',12],['Clarke',13]] df = pd.DataFrame(data,columns=['Name','Age'],dtype=float) print (df)
It should look like below. Click OK:
Now click Load, then Transform Data to open it in the Power Query Editor:
We see the data has been loaded. Click Close and Apply:
In the Power BI Desktop report canvas, select the 2 fields from the df dataset. We see the Age and Name data is displayed. We can now use this Python data source with our Power BI Visuals.
In the next post, we will look at how to use Python to filter data in Power Query.
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL
Didn’t work, until this page i did all the steps as suggested, but i get the following error
Details: “ADO.NET: A problem occurred while processing your Python script.
Here are the technical details: Process must exit before requested information can be determined.”
Hey Patrick,
Do you have pandas installed? Also, are all your data sources set to privacy level Public?
Thanks for answering. I was finally able to make it work. Apparently it was some sort of bug from previous PBI versions.
Hello! I am actually trying to work the other way around. I have a Power BI report full with tables which I am interested on importing as dataframes to Python. Is this possible?
How can I scheduled the refresh of my python script in order to keep my dashboard updated?
If you got the solution please help me too , struggling for the same
Looking for options to run the script in powerbi service. currently the refresh fails on service however i am able to successfully fetch data from using desktop.
After loading the data thru python script, the data got loaded. But if I want to edit the script, can you help me how to do that, is there any option
After loading the data the python script, if I want to edit the script, how to go about it. Are there any options available
What do you have to do to have your Python datasource to be refreshed in Power BI Service?