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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

0

Pandas dataframe column has converted type

When I load in a Python Pandas dataframe with explicitly set string objects in column, this column can get converted to a number (Int or Float) by PowerBI. 

 

It happens when the first X rows of the column look like numbers (not always), but I get errors in later rows that have characters.  I can fix by hand by converting the column's data type to text.  But it would be better if PowerBI used the native column type. 

 

Example df shows the problem

 

import pandas

d= [ [1,'1','a1', 100], [2,'2','b2', 200] ]
c = ['a', 'b', 'c', 'd']

df= pandas.DataFrame(d,columns=c)

 

df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2 entries, 0 to 1
Data columns (total 4 columns):
a 2 non-null int64
b 2 non-null object
c 2 non-null object
d 2 non-null int64
dtypes: int64(2), object(2)
memory usage: 144.0+ bytes

Status: Delivered
Comments
Anonymous
Not applicable

When I load a Python created Pandas dataframe, a string object column can get converted to a number type

 

For example, the script below reads in column 'b' as Int64

 

d = [ [1,'1', 'a1', 100], [2, '2', 'b2', 200] ] 

c= ['a', 'b', 'c', 'd']

df = pandas.DataFrame(d, columns=c)

 

The query shows this

= Table.TransformColumnTypes(df1,{{"a", Int64.Type}, {"b", Int64.Type}, {"c", type text}, {"d", Int64.Type}})

 

I need it to stay as the native Pandas dataframe type, and not manually convert to Text type

v-yuezhe-msft
Microsoft Employee

@Anonymous,

Please uncheck automatically detect column types option as below in your Power BI Desktop report.

1.PNG

Regards,
Lydia

v-yuezhe-msft
Microsoft Employee
Status changed to: Delivered
 
Anonymous
Not applicable

Unfortunately, after unchecking Automatically detect ..

everything comes in as text.  I wanted the native dataframe column type to be retained and used