pandas 的十进制分类舍入 [英] Decimal class rounding in Pandas
本文介绍了 pandas 的十进制分类舍入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Pandas数据框内四舍五入Decimals()
时遇到问题. round()
方法不起作用,也不使用quantize()
.到目前为止,我一直在寻找没有运气的解决方案.
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()
不执行任何操作,我想这是为了浮点数
round()
does nothing, i asume it is meant for float numbers
quantize()
无法使用,因为它不是DataFrame函数
quantize()
won't work because it is not a DataFrame function
有什么想法吗?
推荐答案
由于熊猫没有量化方法,因此我使用以下方法解决了该问题:
Since pandas has no quantize method i used the following to solve the problem:
out.applymap(lambda x: x.quantize(dc.Decimal('1.00')))
这篇关于 pandas 的十进制分类舍入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文