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.