This is a test version of Biostars. For the public version, visit https://www.biostars.org.
increasing floating point precision in pandas

I have a pandas data frame with mixed types

I would like to increase the floating point precision of the columns with float64 to 500 point precision.

Is there an easy solution using decimal library? I'm having some troubles with the current methods.

from decimal import *
getcontext().prec = 500
df['floating'] = df['floating'].astype(Decimal)

df['phred'] = -10 * np.log10(1-df['floating'])

Error:

AttributeError: 'float' object has no attribute 'log10
python pandas floating-point

I hope you've considered whether any of the initial values that you're using even have 500 significant digits.

BTW, this is pretty off-topic.

1 answer

This tiny piece here:

np.log10(1-df['floating'])

seems to cause your problems with log10, did you do import numpy as np in your script, and are you sure that you didn't overwrite "np" with some floating point number?

Log in to answer this question.