rounding

How to round off range of Pandas dataframe columns based on a condition

How to round off range of Pandas dataframe columns based on a condition Question: I am new to python. Below is my dataframe, I want to round the colums COLB to COLE to 0 decimal if the columns are greater than 1 if not I want to assign value 1 Name COLB COLC COLD COLE …

Total answers: 2

Python Prevent Rounding Error with floats

Python Prevent Rounding Error with floats Question: I have checked dozens of other questions on stackoverflow about rounding floats in Python. I have learned a lot about how computers store these numbers, which is the root cause of the issue. However, I have not found a solution for my situation. Imagine the following situation: amount …

Total answers: 3

Rounding Numbers in a Quartile Figures of a Plotly Box Plot

Rounding Numbers in a Quartile Figures of a Plotly Box Plot Question: I have been digging around a while trying to figure out how to round the numbers displayed in quartile figures displayed in the hover feature. There must be a straightforward to do this as it is with the x and y coordinates. In …

Total answers: 2

How can I turn off rounding in Spark?

How can I turn off rounding in Spark? Question: I have a dataframe and I’m doing this: df = dataframe.withColumn("test", lit(0.4219759403)) I want to get just the first four numbers after the dot, without rounding. When I cast to DecimalType, with .cast(DataTypes.createDecimalType(20,4) or even with round function, this number is rounded to 0.4220. The only …

Total answers: 2

Python rounding with Decimal module to specified decimal places

Python rounding with Decimal module to specified decimal places Question: Question: How could I make Python’s Decimal module round to a specified decimal place instead of rounding to a specified precision (significant figure) while evaluating an arithmetic operation? Info I have been using the Decimal module in Python to round values to a specified precision …

Total answers: 2

Function in python that outputs either -1 or 0 or 1

Function in python that outputs either -1 or 0 or 1 Question: Is there like a (modified) round function where the output would be either -1,0,1 depending on to what number is the input the closest? E.g. 0 => 0, -2154 => -1, 10 => 1 Currently I am using normal if else statements: if …

Total answers: 3

Round decimal – If 1 then no decimal, if 0.01 then 2 decimal

Round decimal – If 1 then no decimal, if 0.01 then 2 decimal Question: How can i truncate not with casual number like 1, 2, 3 but directly with decimal syntax? For example: I have 4 and decimal to 1 so truncate to 4. I have 1.5 and decimal to 1 so truncate to 1. …

Total answers: 4

How to round away from zero

How to round away from zero Question: I am new to python, and as far as I found out, python doesn’t have sort of “mathematical” rounding. Or does it have? I have a temperature array, for example: temp = [-20.5, -21.5, -22.5, -23.5, 10.5, 11.5, 12.5, 13.5] I couldn’t fine the way to round values …

Total answers: 3