Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing scientific notation in pandas?

I have a DataFrame in pandas where some of the numbers are expressed in scientific notation (or exponent notation) like this:

                  id        value id              1.00    -4.22e-01 value          -0.42     1.00e+00 percent        -0.72     1.00e-01 played          0.03    -4.35e-02 money          -0.22     3.37e-01 other            NaN          NaN sy             -0.03     2.19e-04 sz             -0.33     3.83e-01 

And the scientific notation makes what should be an easy comparison, needlessly difficult. I assume it's the 21900 value that's screwing it up for the others. I mean 1.0 is encoded. ONE!

This doesn't work:

np.set_printoptions(supress=True)  

And pandas.set_printoptions doesn't implement suppress either, and I've looked all at pd.describe_options() in despair, and pd.core.format.set_eng_float_format() only seems to turn it on for all the other float values, with no ability to turn it off.

like image 243
user1244215 Avatar asked Jul 19 '13 02:07

user1244215


People also ask

How do you stop scientific notation in Python?

Approach: If you are using an older version of Python, use %. nf to suppress the scientific notation to a floating-point value upto n decimal places.

How do I print without scientific notation in Python?

Within a given f-string, you can use the {...:f} format specifier to tell Python to use floating point notation for the number preceding the :f suffix. Thus, to print the number my_float = 0.00001 non-scientifically, use the expression print(f'{my_float:f}') .

How do you cancel scientific notation?

(1) Right-click a cell where you want to remove scientific notation, and (2) choose Format Cells… 2. In the Format Cells window, (1) select the Number category, (2) set the number of decimal places to 0, and (3) click OK. Now the scientific notation is removed.


1 Answers

quick temporary: df.round(4)

global: pd.options.display.float_format = '{:20,.2f}'.format

like image 103
citynorman Avatar answered Oct 06 '22 08:10

citynorman