Nov-06-2018, 08:08 PM
(Nov-06-2018, 07:22 PM)ichabod801 Wrote: Well, map is built-in to the DataFrame, and lambda and round are built-in to Python, so that is something built-in.
As to why it won't accept Decimal, I'm not sure. TypeError makes me think it's conflicting with the type of the column. Can you post the full line of code and the full traceback?
The code is Decimal((df['value1'])).quantize(Decimal("0.01"), decimal.ROUND_HALF_UP)
which produces the below
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-85-8612a11132b8> in <module>()
----> 1 Decimal((df['value1'])).quantize(Decimal("0.01"), decimal.ROUND_HALF_UP)
C:\Users\Owner\Anaconda2\lib\decimal.pyc in __new__(cls, value, context)
655 return self
656
--> 657 raise TypeError("Cannot convert %r to Decimal" % value)
658
659 # @classmethod, but @decorator is not valid Python 2.3 syntax, so
TypeError: Cannot convert 0 0.121
1 0.122
2 0.123
3 0.124
4 0.125
5 0.126
6 0.127
7 0.128
8 0.129
9 0.130
Name: value1, dtype: float64 to Decimal