0

When I am using to_numeric() convert my string values to float. The values are getting rounded off. How to avoid it?

import numpy as np
import pandas as pd

s = pd.Series(['1.1122334455', '2.1112223334444', -3.234234234234324])
print(pd.to_numeric(s))

Output:

0    1.112233
1    2.111222
2   -3.234234
dtype: float64

I want all the decimal values or at least 11 for my requirement. Any help will be appreciated.

K.P.
  • 105
  • 1
  • 9

1 Answers1

0

No, its not getting rounded off, that's how it gets printed in the terminal. But if you try to print specific value, you'll see all those digits after decimal:

>>> pd.to_numeric(s).iloc[1]
2.1112223334444

And its controlled by precision option of display:

>>> pd.options.display.precision = 11
>>> pd.to_numeric(s)

0    1.11223344550
1    2.11122233344
2   -3.23423423423
dtype: float64

Look at Available Options in pandas docs for more.

ThePyGuy
  • 17,779
  • 5
  • 18
  • 45