Search code examples
pythonpandasdataframedescribe

Output formatting in pandas describe


I have some problems with formatting describe table from pandas. I would love to have 2 decimals precision in every column, but in last I need to have 1.11e11 format. I have tried applying

data.styles.format({"last_column": "{:.2E}"})

, but it does not seem to work for me, still the same result as can be seen below.

Things like: pd.set_option('display.float_format', '{:.2E}'.format) is applied pandas-wide, which is not what I want to do.

print(data.describe(percentiles=[],).fillna("-.--").round(2))
count           1               1               1             1        1               1
mean         1.43             0.4           34.58          0.07     0.71     1.12877e+08
std          -.--            -.--            -.--          -.--     -.--            -.--
min          1.43             0.4           34.58          0.07     0.71     1.12877e+08
50%          1.43             0.4           34.58          0.07     0.71     1.12877e+08
max          1.43             0.4           34.58          0.07     0.71     1.12877e+08

I would like to evade if tabulate, or any other tabular tool if possible, would like to solve this on level of pandas.

Does anyone please have a solution? Thank you :)


Solution

  • Just use this:-

    pd.set_option('precision',2)
    

    and if you want to reset it back to original form i.e its default value then use this:-

    pd.reset_option('precision')