我试图在熊猫数据框中舍入十进制类型,并不断出现以下错误:
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)