如何舍入十进制类型

时间:2019-07-17 20:37:49

标签: python-3.x

我试图在熊猫数据框中舍入十进制类型,并不断出现以下错误:

unsupported operand type(s) for *: 'decimal.Decimal' and 'float'

我尝试了以下代码的多种变体:

import pandas as pd
from decimal import Decimal

data = pd.DataFrame({"Rate" : [25.25,30.12,35.3,40.12,45.31]})
data['Rate'] = data['Rate'].apply(Decimal)
data['New_Rate']=(data['Rate'] * Decimal(.02)) + data['Rate']
data['Round_Rate']=round(data['New_Rate'],2)

0 个答案:

没有答案