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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
vmerida
Frequent Visitor

Python Script Error

Hello, I was running the following Python script:

import pandas as pd

df = pd.DataFrame({

'Fname':['Harry','Sally','Paul','Abe','June','Mike','Tom'],

'Age':[21,34,42,18,24,80,22], 'Weight': [180, 130, 200, 140, 176, 142, 210],

'Gender':['M','F','M','M','F','M','M'],

'State':['Washington','Oregon','California','Washington','Nevada','Texas','Nevada'],

 'Children':[4,1,2,3,0,2,0], 'Pets':[3,2,2,5,0,1,5] })

print (df)

 

the script cretaed the data frame without any error but when Power BI try to load the table in the model (connection to the model) I receive the following error:

"Failed to save modifications to the server. Error returned: 'Expression in partition 'n/a' in table 'n/a' references unknown variable or function 'Python.Execute'. '."

 

I have installed:

  • Windows 10 Professional x64 (Version: 1909 - Build: 18363.720)
  • Power BI Desktop x64 (Version: 2.79.5768.721 - March 2020)
  • Python: Python 3.8.2 x64 (I try the same python script using Anaconda Python 3.7.6 x64, but this version gives me more errors)

This is the Session Diagnostics from Power BI Desktop:

Feedback Type:
Frown (Error)

Timestamp:
2020-03-29T12:55:05.3504335Z

Local Time:
2020-03-29T08:55:05.3504335-04:00

Session ID:
fd38f850-8e8b-44f3-a910-1eec36fa43be

Release:
March 2020

Product Version:
2.79.5768.721 (20.03) (x64)

OS Version:
Microsoft Windows NT 10.0.18363.0 (x64 en-US)

CLR Version:
4.7 or later [Release Number = 528040]

Peak Virtual Memory:
38.5 GB

Private Memory:
644 MB

Peak Working Set:
766 MB

IE Version:
11.719.18362.0

User ID:
6fa195ba-dfc3-4ffb-876e-6fccdd8617ea

Workbook Package Info:
1* - en-US, Query Groups: 0, fastCombine: Enabled, runBackgroundAnalysis: True.

Telemetry Enabled:
False

Snapshot Trace Logs:
C:\Users\vicen\AppData\Local\Microsoft\Power BI Desktop\FrownSnapShot763307589.zip

Model Default Mode:
Empty

Model Version:
PowerBI_V1

Is Report V3 Models Enabled:
True

Performance Trace Logs:
C:\Users\vicen\AppData\Local\Microsoft\Power BI Desktop\PerformanceTraces.zip

Enabled Preview Features:
PBI_shapeMapVisualEnabled
PBI_SpanishLinguisticsEnabled
PBI_NewWebTableInference
PBI_qnaLiveConnect
PQ_AIInsightsFunctionBrowser
PBI_realTimeRefresh
PBI_showMinervaRibbon
PBI_showMinervaViewNavigator
PBI_v3Models
PBI_decompositionTree
PBI_themeDialog
PBI_hierarchicalSlicerCreation

Disabled DirectQuery Options:
TreatHanaAsRelationalSource

Cloud:
GlobalCloud

DPI Scale:
100%

Supported Services:
Power BI

Formulas:


section Section1;

shared df = let
Source = Python.Execute("import pandas as pd #(lf)df = pd.DataFrame({ #(lf) 'Fname':['Harry','Sally','Paul','Abe','June','Mike','Tom'], #(lf) 'Age':[21,34,42,18,24,80,22], #(lf) 'Weight': [180, 130, 200, 140, 176, 142, 210], #(lf) 'Gender':['M','F','M','M','F','M','M'], #(lf) 'State':['Washington','Oregon','California','Washington','Nevada','Texas','Nevada'],#(lf) 'Children':[4,1,2,3,0,2,0],#(lf) 'Pets':[3,2,2,5,0,1,5] #(lf)}) #(lf)print (df) "),
df1 = Source{[Name="df"]}[Value],
#"Changed Type" = Table.TransformColumnTypes(df1,{{"Fname", type text}, {"Age", Int64.Type}, {"Weight", Int64.Type}, {"Gender", type text}, {"State", type text}, {"Children", Int64.Type}, {"Pets", Int64.Type}})
in
#"Changed Type";

shared #"df (2)" = let
Source = Python.Execute("import pandas as pd #(lf)df = pd.DataFrame({ #(lf) 'Fname':['Harry','Sally','Paul','Abe','June','Mike','Tom'], #(lf) 'Age':[21,34,42,18,24,80,22], #(lf) 'Weight': [180, 130, 200, 140, 176, 142, 210], #(lf) 'Gender':['M','F','M','M','F','M','M'], #(lf) 'State':['Washington','Oregon','California','Washington','Nevada','Texas','Nevada'],#(lf) 'Children':[4,1,2,3,0,2,0],#(lf) 'Pets':[3,2,2,5,0,1,5] #(lf)}) #(lf)print (df) "),
df1 = Source{[Name="df"]}[Value],
#"Changed Type" = Table.TransformColumnTypes(df1,{{"Fname", type text}, {"Age", Int64.Type}, {"Weight", Int64.Type}, {"Gender", type text}, {"State", type text}, {"Children", Int64.Type}, {"Pets", Int64.Type}})
in
#"Changed Type";

shared #"df (3)" = let
Source = Python.Execute("import pandas as pd #(lf)df = pd.DataFrame({ #(lf) 'Fname':['Harry','Sally','Paul','Abe','June','Mike','Tom'], #(lf) 'Age':[21,34,42,18,24,80,22], #(lf) 'Weight': [180, 130, 200, 140, 176, 142, 210], #(lf) 'Gender':['M','F','M','M','F','M','M'], #(lf) 'State':['Washington','Oregon','California','Washington','Nevada','Texas','Nevada'],#(lf) 'Children':[4,1,2,3,0,2,0],#(lf) 'Pets':[3,2,2,5,0,1,5] #(lf)}) #(lf)print (df) "),
df1 = Source{[Name="df"]}[Value],
#"Changed Type" = Table.TransformColumnTypes(df1,{{"Fname", type text}, {"Age", Int64.Type}, {"Weight", Int64.Type}, {"Gender", type text}, {"State", type text}, {"Children", Int64.Type}, {"Pets", Int64.Type}})
in
#"Changed Type";

1 ACCEPTED SOLUTION

Hi Lewis,

I know the Python Script work, but when I try en Power BI it give me a error...

 

Yesterday I fixed the problem. I uninstalled and install again: Python, Anaconda, Power BI and VS Code, after that the Python program work in Power BI…

 

Thank you for you help...

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

I think the main issue is here in the error message...

TypeError: from_bounds() takes 4 positional arguments but 6 were given

 

The line that Python was trying to execute was this:

self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)

 

Maybe get rid of the 0's?

Are you trying to make a visual or uploading data using python script?

Have you tested out the code in an IDE?

Hi Lewis,

I know the Python Script work, but when I try en Power BI it give me a error...

 

Yesterday I fixed the problem. I uninstalled and install again: Python, Anaconda, Power BI and VS Code, after that the Python program work in Power BI…

 

Thank you for you help...

v-lionel-msft
Community Support
Community Support

Hi @vmerida ,

 

As tested, I can import your python script successfully.

ccc1.PNG

ccc2.PNG

let
    Source = Python.Execute("import pandas as pd#(lf)#(lf)df = pd.DataFrame({#(lf)#(lf)'Fname':['Harry','Sally','Paul','Abe','June','Mike','Tom'],#(lf)#(lf)'Age':[21,34,42,18,24,80,22], 'Weight': [180, 130, 200, 140, 176, 142, 210],#(lf)#(lf)'Gender':['M','F','M','M','F','M','M'],#(lf)#(lf)'State':['Washington','Oregon','California','Washington','Nevada','Texas','Nevada'],#(lf)#(lf) 'Children':[4,1,2,3,0,2,0], 'Pets':[3,2,2,5,0,1,5] })#(lf)#(lf)print (df)"),
    df1 = Source{[Name="df"]}[Value],
    #"Changed Type" = Table.TransformColumnTypes(df1,{{"Fname", type text}, {"Age", Int64.Type}, {"Weight", Int64.Type}, {"Gender", type text}, {"State", type text}, {"Children", Int64.Type}, {"Pets", Int64.Type}})
in
    #"Changed Type"

Maybe you can try to use my M code.

My Power BI version: 2.79.5768.663 64-bit (March 2020)

My python: python38-32

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Lionel,

I know the Python Script work, but when I try en Power BI it give me a error...

 

Yesterday I fixed the problem. I uninstalled and install again: Python, Anaconda, Power BI and VS Code, after that the Python program work in Power BI…

 

Thank you for you help…

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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