0

I would like to gain space while saving my datas, I don't mind the loss of information. The data have many different of order of magnitude, So I cannot round using the normal rounding function. I can't seem to find a post that help me to round my dataset using scientific numbers

12345678 => round with 3 decimals => 1.234E7

Any help is appreciated :)

th0mash
  • 185
  • 3
  • 13

1 Answers1

1

You can use to_csv with a float_format='%.3E' to ouput your (floating point) data rounded to 3 places in scientific notation to a csv file. See the format specification for other formatting options.

Minimal example:

pd.DataFrame([12345678]).astype(float).to_csv(float_format='%.3E')
#',0\r\n0,1.235E+07\r\n'

There's no easy way to have E7 instead of E+07, see also this SO question.

Stef
  • 28,728
  • 2
  • 24
  • 52