pd.DataFrame cuts the decimals' mantissa

112 Views Asked by At

Need to convert list of values with long mantissa into pd.DataFrame without precision lost:

enter image description here

My list of decimals:

enter image description here

The way pd.DataFrame convert it.

1

There are 1 best solutions below

0
Simone On BEST ANSWER

The values are stored with the correct precision, they are just truncated when you display them.

You can change the precision used by pandas when displaying datarames by using pd.set_option('display.precision', num_decimal_digits).

For example

df = pd.DataFrame([0.123456789])

print('Before setting precision:')
print(df)
pd.set_option('display.precision', 9)
print('After setting precision:')
print(df)

prints

Before setting precision:
          0
0  0.123457
After setting precision:
             0
0  0.123456789