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
Datalewis
Regular Visitor

Python for Power B: Invalid Decimal Literal Syntax error

I am having trouble getting python visual and scripts to run in powerbi

 

I am trying to import the following test script as a datasource taken from the power BI documentation website https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-visuals

 

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)

 

This gives the following error

Details: "ADO.NET: Python script error.
<pi> File "C:\Users\NirmalaD'souza\PythonScriptWrapper_fb8dadbe-f2ff-41ee-8115-53ff4a4bbbcd\PythonScriptWrapper.PY", line 9
os.chdir(u'C:/Users/NirmalaD'souza/PythonScriptWrapper_fb8dadbe-f2ff-41ee-8115-53ff4a4bbbcd')
^
SyntaxError: invalid decimal literal
</pi>"

 

I have python installed in the following location - C:\Program Files\Python311 and have set this as home directory in python script options

 

trying to run other premade scripts from online to produce visuals produces similar results

 

Any idea why this doesn't work?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Datalewis ,

First check the prerequisites.

vcgaomsft_0-1693291639725.png

Use the pip list command to check that the necessary libraries are installed. (Restart your computer after installing the library)

vcgaomsft_1-1693291739212.png
Ensure that you have the correct Python version and required packages installed. Power BI might be using a different Python version than the one you have installed. You can check the Python version used by Power BI Desktop under Options > Python Scripting.
I also made a simple example according to the documentation, please check if the pbix file works properly on your computer.

vcgaomsft_2-1693292236270.png

 

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Datalewis , Try like

 

import pandas as pd
import os

# Escape the single quote in the directory path
directory_path = r"C:/Users/NirmalaD\'souza/PythonScriptWrapper_fb8dadbe-f2ff-41ee-8115-53ff4a4bbbcd"
os.chdir(directory_path)

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)
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi 

 

Thank you for your response!!!

 

I tried and got the following error

 

Details: "ADO.NET: Python script error.
<pi> File "C:\Users\NirmalaD'souza\PythonScriptWrapper_cfa2403b-8384-422b-acbc-272ddaf1489b\PythonScriptWrapper.PY", line 9
os.chdir(u'C:/Users/NirmalaD'souza/PythonScriptWrapper_cfa2403b-8384-422b-acbc-272ddaf1489b')
^
SyntaxError: invalid decimal literal
</pi>"

 

To clarify, in case im trying to use the program incorrectly: my process is taking a new blank power BI project, Get Data -> More -> Other -> Python Scrpt and then copying in the code fragment

 

Cheers

Anonymous
Not applicable

Hi @Datalewis ,

First check the prerequisites.

vcgaomsft_0-1693291639725.png

Use the pip list command to check that the necessary libraries are installed. (Restart your computer after installing the library)

vcgaomsft_1-1693291739212.png
Ensure that you have the correct Python version and required packages installed. Power BI might be using a different Python version than the one you have installed. You can check the Python version used by Power BI Desktop under Options > Python Scripting.
I also made a simple example according to the documentation, please check if the pbix file works properly on your computer.

vcgaomsft_2-1693292236270.png

 

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

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.