问题
i have problems rounding Decimals()
inside a Pandas Dataframe. The round()
method does not work and using quantize()
neither. I've searched for a solution with no luck so far.
round()
does nothing, i asume it is meant for float numbers
quantize()
won't work because it is not a DataFrame function
Any thoughts?
回答1:
Since pandas has no quantize method i used the following to solve the problem:
out.applymap(lambda x: x.quantize(dc.Decimal('1.00')))
回答2:
To round your decimal to 2 significant figures for example:
round(df['yourSeries'].astype('float'), 2)
Or if you just want an int:
round(df['yourSeries'].astype('float'))
来源:https://stackoverflow.com/questions/54773447/decimal-class-rounding-in-pandas