Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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
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
User | Count |
---|---|
98 | |
90 | |
77 | |
71 | |
64 |
User | Count |
---|---|
115 | |
102 | |
98 | |
71 | |
67 |