Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas data precision [duplicate]

Tags:

python

pandas

By default the numerical values in data frame are stored up to 6 decimals only. How do I get the full precision.

For example
34.98774564765 is stored as 34.987746. I do want the full value.

and 0.00000565 is stored as 0. .

Apart from applying formats to each data frame is there any global setting that helps preserving the precision.

Thanks

like image 261
user7789097 Avatar asked Apr 04 '17 21:04

user7789097


People also ask

What is Panda precision?

Your data is stored with the precision, corresponding to your dtype ( np. float16 , np. float32 , np. float64 ). pd.options.display.precision - allows you to change the precision for printing the data.

How do you check if there is duplicate in pandas?

To find duplicates on a specific column, we can simply call duplicated() method on the column. The result is a boolean Series with the value True denoting duplicate.


2 Answers

No, 34.98774564765 is merely being printed by default with six decimal places:

>>> pandas.DataFrame([34.98774564765])
           0
0  34.987746

The data itself has more precision:

>>> pandas.DataFrame([34.98774564765])[0].data[0]
34.98774564765

You can change the default used for printing frames by altering pandas.options.display.precision.

For example:

>>> pandas.set_option("display.precision", 8)
>>> pandas.DataFrame([34.98774564765])
                0
0  34.98774564765
like image 101
donkopotamus Avatar answered Sep 18 '22 16:09

donkopotamus


You can also use the 'display.float_format' option

with pd.option_context('display.float_format', '{:0.20f}'.format):
    print(pd.DataFrame([34.98774564765]))

                        0
0 34.98774564765000150146
like image 40
piRSquared Avatar answered Sep 19 '22 16:09

piRSquared