Python Forum
Panda Dataframe Rounding Issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Panda Dataframe Rounding Issue
#5
(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
Reply


Messages In This Thread
Panda Dataframe Rounding Issue - by ab0217 - Nov-06-2018, 06:41 PM
RE: Panda Dataframe Rounding Issue - by ichabod801 - Nov-06-2018, 07:02 PM
RE: Panda Dataframe Rounding Issue - by ab0217 - Nov-06-2018, 07:10 PM
RE: Panda Dataframe Rounding Issue - by ichabod801 - Nov-06-2018, 07:22 PM
RE: Panda Dataframe Rounding Issue - by ab0217 - Nov-06-2018, 08:08 PM
RE: Panda Dataframe Rounding Issue - by ichabod801 - Nov-06-2018, 10:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding a new column to a Panda Data Frame rsherry8 2 2,971 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  Issue with dataframe column nsadams87xx 0 2,576 May-29-2020, 02:00 AM
Last Post: nsadams87xx
  How to filter data using a panda.DateFrame.loc pawlo392 1 3,221 May-27-2019, 08:47 PM
Last Post: michalmonday
  Make panda dataframe output pretty carstenlp 2 4,610 Jan-17-2019, 10:04 AM
Last Post: carstenlp
  panda, excel - script pauses and doesn't continue running, no error message william 1 3,212 Nov-24-2018, 01:24 AM
Last Post: ichabod801
  DataFrame index issue Astrikor 2 3,644 Aug-25-2018, 04:25 PM
Last Post: Astrikor
  rounding Stevger 0 2,409 Mar-13-2018, 09:32 PM
Last Post: Stevger
  Replacing values for specific columns in Panda data structure Padowan 1 15,289 Nov-27-2017, 08:21 PM
Last Post: Padowan
  Panda.read_cvs Issues Reading Certain Columns BlackHeart 5 7,477 Oct-27-2017, 04:29 PM
Last Post: Larz60+
  Panda Data Frame to Existing Multiple Sheets naveedraza 1 6,316 Jul-11-2017, 12:21 PM
Last Post: naveedraza

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020