Home > Blockchain >  pd.DataFrame cuts the decimals' mantissa
pd.DataFrame cuts the decimals' mantissa

Time:10-23

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

CodePudding user response:

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
  • Related