Search code examples
pythonpandasdataframedescribe

pd.describe(include=[np.number]) return 0.00


I use the df_30v.describe(include=[np.number]) to give me the summary on my variables in the data frame. However the result is something with too many digit

count 235629.000000 235629.000000 235629.000000 119748.000000

how can i get the below as a result. Thank you!

count 235629.00 235629.00 235629.00 119748.00


Solution

  • Call pd.set_option('precision', 2):

    In [165]: pd.set_option('precision', 2)
    In [167]: df = pd.DataFrame(np.random.uniform(0, 10**6, size=(100,5)))
    In [168]: df.describe()
    Out[168]: 
                   0          1          2          3          4
    count     100.00     100.00     100.00     100.00     100.00
    mean   440786.89  526477.58  457295.14  498070.00  481541.09
    std    286118.94  264010.57  312539.39  310191.95  274682.03
    min       677.71   11862.05    2934.92   13031.54   11728.73
    25%    244739.83  316760.73  188148.99  207720.23  222285.78
    50%    411391.98  527119.36  406672.95  496606.54  476422.05
    75%    637488.49  741362.83  745412.65  778365.74  701966.74
    max    993927.91  990323.15  998025.25  999628.94  998598.52
    

    Or, to change the precision temporarily for a block of code, use a context manager:

    with pd.option_context('precision', 2):
        df = pd.DataFrame(np.random.uniform(0, 10**6, size=(100,5)))
        print(df.describe())