Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I'm learning to import data via python script following Microsoft tutorial (https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts). I have installed python, pandas, matplotlib package in local machine under path C:\Users\yyy.xxx\Anaconda3\Lib\site-packages\matplotlib
In my Power BI desktop, Get Data - Python Script, I input the following script:
*******************************************************************
import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
print (df)
***************************************************
Below is the error message from Power BI after running the script:
Solved! Go to Solution.
works fine for me. Re-do your Python setup on that PC.
No need to print the variable.
let
Source = Python.Execute("import pandas as pd#(lf)data = [['Alex',10],['Bob',12],['Clarke',13]]#(lf)df = pd.DataFrame(data,columns=['Name','Age'])"),
df1 = Source{[Name="df"]}[Value]
in
df1
As an addition to the discussion above, I found out later that Power BI only support very limited python package, so even if a python script works in PB Desktop, it may still fail to refresh after publishing to PB Service. So a real solution should be create the python script in Fabric Notebook and import data from Fabric to Power BI Desktop.
So I am also creating a data model via python, and it works fine on my desktop. However while I can deploy the model to service I don't see a way that I can have PBI Service refresh the model for me. Is this just a limitation of PBI service and the on-prem gateway or am I missing something.
a service refresh MANDATES the use of a PERSONAL gateway.
Thank you! Problem solved.
Here are the steps I have taken:
1. the error message shows there is problem with importing os, pandas, matplotlib. My assumption is those packages has to be installed in the same folder as python. So to fix this, I opened cmd, type "pip installed pandas", this time I got an error message that pandas can not be installed.
*************************************************************************************************************************
Collecting six>=1.5
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: pytz, tzdata, six, numpy, python-dateutil, pandas
WARNING: Failed to write executable - trying to use .deleteme logic
ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: 'C:\\Python311\\Scripts\\f2py.exe' -> 'C:\\Python311\\Scripts\\f2py.exe.deleteme'
****************************************************************************************************************
I checked the error message, some people said it's because I didn't install python with admin rights. I uninstalled python 311 and went back to cmd, type "pip install pandas", "pip install matplot lib". This time I got no error message. after installed both packages, I was able to run the python script in power bi.
P.s. i'm new to python coding. So I'm not sure why "pip install pandas" failed at the first time. Uninstall python doesn't seem to impact python coding in later phases.
works fine for me. Re-do your Python setup on that PC.
No need to print the variable.
let
Source = Python.Execute("import pandas as pd#(lf)data = [['Alex',10],['Bob',12],['Clarke',13]]#(lf)df = pd.DataFrame(data,columns=['Name','Age'])"),
df1 = Source{[Name="df"]}[Value]
in
df1
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
69 | |
68 | |
40 | |
29 | |
26 |
User | Count |
---|---|
87 | |
49 | |
45 | |
38 | |
37 |