pandas to csv without converting object to scientific notation

63 views Asked by At

df['Acolumn']='85236E106'

When i df.to_csv('file') it outputs as '8.523600000000001e+110'

how can i convert to csv and leave the value as '85236E106' ?

I tried:

  • float_format='%f' and output = a really long float instead of '85236E106'
  • float_format='{:f}'.format and output = a really long float instead of '85236E106'
  • df['col']=str(df['col']) and output = '8.523600000000001e+110'
  • df['col']=df['col'].astype(str) and output = '8.523600000000001e+110'
  • encoding='utf-8' and output = no difference
  • Column::text in read_sql and output = doesn't work
  • CONVERT(text, Id) in read_sql and output = doesn't work
  • CAST(Id AS varchar) in read_sql and output = doesn't work
  • coerce_float=False in read_sql and output = doesn't work
1

There are 1 answers

0
Kaizar On

I just ran the file again and i'm not sure why df['Acolumn']='85236E106' is now not being converted to scientific notation. I'm using to_csv with only index=False as parameters. However I've added dtype={'Acolumn': pd.StringDtype()} to pd.read_sql_query just incase.