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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Transform Run Python Script Step Data Types

Hello Power BI users,

 

When using a Run Python Script transformation in Power BI using pandas all integer/float columns have the Text data type after the transformation and need to be changed back to number. As the dataset is large I expect this transformation to text and back to number consumes a lot of unnecessary computing power.

 

Additionaly, when converting the text to decimal number, the decimal seperator is interpreted incorrectly, causing "1.0" to be converted to "10", instead of "1,0".

 

The optimal solution would be to allow numerical columns added in a Run Python Scripts step to be interpreted as decimal/whole numbers instead of text.

 

Run Python Script Step

 

# 'dataset' holds the input data for this script

dataset['ones_int'] = 1

dataset['ones_int_dtype'] =dataset['ones_int'].dtype

dataset['ones_float'] = 1.0

dataset['ones_float_dtype'] = dataset['ones_float'].dtype

 

Output of Run Python Script step (note "ones_int" and "ones_float" are of type ABC, thus text )

 

python_script_data_types.png

 

Output of changing column types (note "ones_float" are converted to 10 instaed of 1,0)

 

python_script_data_types_converted.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello Power BI Community,

 

After a few weeks I found the solution and it is embarrassingly simple, just add "en-US" to the changed type step. Thus the changed type step becomes:

 

python_script_data_types_converted_solution.png

 

 

View solution in original post

4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

Hello Power BI Community,

ENGLISH

After a few weeks I found the solution and it is embarrassingly simple, just add "en-US" to the changed type step. Thus the changed type step becomes:

SPANISH

After a few weeks, I found the solution and it is embarrassingly simple, just add "en-US" to the modified type step. Therefore, the changed type step becomes:

python_script_data_types_converted_solution.png

Anonymous
Not applicable

Hello Power BI Community,

 

After a few weeks I found the solution and it is embarrassingly simple, just add "en-US" to the changed type step. Thus the changed type step becomes:

 

python_script_data_types_converted_solution.png

 

 

V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Have you defined the data type in the script? 

import pandas as pd
data = [['A',1],['B',2],['C',3]]
df = pd.DataFrame (data, columns=['type','value'], dtype=float)
print(df)

 

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

Anonymous
Not applicable

Hi @V-lianl-msft,

 

The problem occurs when reading the data back in Power BI, thus after the Python Script Step. In Python the data type is for example float64, however Power BI interprets it as text.

 

The data types of the Pandas DataFrame are thus not correctly interpreted in Power BI after processing the data in Python, int64 and float64 are both interpreted as text.

 

Kind regards,

 

Mark

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors