pandasdataframedecimalmantissa

pd.DataFrame cuts the decimals' mantissa


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.


Solution

  • 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