Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Jeanxyz
Impactful Individual
Impactful Individual

get data via python script

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:

 

 python pb error.PNG

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

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

 

lbendlin_0-1714670705800.png

 

 

View solution in original post

5 REPLIES 5
Jeanxyz
Impactful Individual
Impactful Individual

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. 

id013
Helper V
Helper V

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.

Jeanxyz
Impactful Individual
Impactful Individual

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.

lbendlin
Super User
Super User

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

 

lbendlin_0-1714670705800.png

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.