0

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

Pumpkin C
  • 1,452
  • 6
  • 21
  • 27
  • Possible duplicate: https://stackoverflow.com/a/11708664/190597 (but there is so much information on that page, the solution is a little hard to find.) Perhaps someone knows a better dupe target. – unutbu Aug 24 '17 at 00:54

1 Answers1

0

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())
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677