1

I have 2 Pandas dataframes, with thousands of values. I load them from a csv file with Pandas' read_csv function. I need to subtract a column ("open") of the second one from a column of the first, and i do it like this:

subtraction = shiftedDataset.open - dataset.open

And i get a series with the results. The problem is the results come with the weird rounding that comes from the floating point arithmetic. (e.g. a value that should be 0.00003 is -2.999999999997449e-05)

How can i get the correct results? I can manipulate the dataframe before the subtraction or the values after the subtraction, i don't care, but i need to get the best performance possible.

dgtal
  • 193
  • 16

1 Answers1

0

This is scientific notation, and is probably more accurate if you want to do more calculations. If this is purely for display purposes, look at this post

Example:

v = -2.999999999997449e-05
print('%f' % v)
>>> '-0.000030'

Some are for formatting the output (tuning your value into a string, might not be what you want), but there's also a pandas setting you can use (also on the same post, scroll down a bit).

Community
  • 1
  • 1
Xhattam
  • 195
  • 1
  • 11