0

I wrote python code to return the count of each levels of a feature of a h2o dataframe, but the result always come back in scientific notation. How do I get it to display using decimal?

Code I used:

print(all_propensity["HasLoss"].table())

What it returns:
HasLoss    Count
0                1.46457e+07
1                35277


What I want it to return:
HasLoss    Count
0                14,645,700
1                35,277

floydn
  • 1,083
  • 7
  • 14
CHW
  • 31
  • 2

1 Answers1

1

In R you would use options(digits=12), or something like that, to not have it use scientific precision until that number of digits. But in Python there seems no way to override the global default (which I think is 6 digits), and all the answers I found were about doing the formatting yourself.

But you can control it in ipython/Jupyter with:

%precision 12

(See https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-precision )

Or, assuming you have pandas imported, the table H2O returns is actually a pandas table, so there are formatting options there. I think pd.options.display.float_format = '{:.0f}'.format would do it. Or change the column data type to an int64, as suggested here: https://stackoverflow.com/a/49910142/841830

All the options for pandas are here: https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html#available-options or search for pandas ways to format data. (I.e. just remember that H2O gives you a pandas data set, so it is a pandas question once you have the data in python.)

Darren Cook
  • 27,837
  • 13
  • 117
  • 217
  • Thank you so much. I ended up converting it to panda frame and used the display format. – CHW Sep 03 '19 at 21:35