Search code examples
pythonpandasscientific-notation

Dataframe with conflicting float formatting


I have the below dataframe:

pd.DataFrame({'Full Dataset': m1_baseline.params,
          'Train Set': m1_train.params})

Which produces the below table:

                     Full Dataset   Train Set
Intercept            6.078966e+01    62.479667
DISTANCE             4.418002e-03    0.001389
AP_TOTAL_ARRIVALS   -8.944526e-07   -0.000006
AL_TOTAL_FLIGHTS    -7.643211e-06   -0.000008
Lunch               -4.391630e+00   -5.179138

Obviously the use of scientific notation in the first column but not the second is confusing.

Is there a way to fix this?


Solution

  • You can try df.style:

    df.style.format('{:.2f}')
    

    This fill have numbers upto 2 decimal places and you can change the number to change it how many ever decimal places you want