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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Jeanxyz
Post Prodigy
Post Prodigy

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

2 REPLIES 2
Jeanxyz
Post Prodigy
Post Prodigy

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.