0

I want to save a dataframe which has numeric values into a csv using df.to.csv command in pandas and avoid conversion of the values to scientific notation.

I have a dataframe which looks like this:

d = {'CookieID': [8034109298000000000, 6180638274000000000], 'Junk': [CryptIDsOptOut, CryptIDsOptOut]}

When I save it to csv using

dffound.to_csv(r'C:\Users\Output_4.csv', index=False, header=False, sep='\t')

it converts it to scientific notation like in this file.

I want to avoid this and save it as the it appears in the dataframe without any conversions. Thank you for your help.

asda1
  • 1
  • 2

1 Answers1

0
dffound.to_csv(r'C:\Users\Output_4.csv', index=False, header=False, sep='\t',float_format='%.0f')
Will
  • 1,619
  • 5
  • 23
  • This added some decimal points after the number. I am trying to avoid them. Can you help me out. For ex., i got in Cell A1: 8034109297765175296.000000000000000 – asda1 Nov 03 '22 at 09:52
  • replace it with `float_format='%.0f'` – D_action Nov 03 '22 at 09:56
  • @asda1 I misunderstood the problem. I edited the answer. Now it should work – Will Nov 03 '22 at 09:59
  • There is still an error as if you notice, the first cell was 8034109298000000000. Your code seems to be changing the value to 8034109297765175296. This is not what I desire. I want the same number as initially. – asda1 Nov 03 '22 at 10:02
  • try the solution of this [https://stackoverflow.com/questions/56345170/prevent-trailing-zero-with-pandas-to-csv](post) – D_action Nov 03 '22 at 10:17