Am using following function:
def round_half_away_from_zero(n, decimals=1):
rounded_abs = round_half_up(abs(n), decimals)
return math.copysign(rounded_abs, n)
def round_half_up(n, decimals=1):
multiplier = 10 ** decimals
return math.floor(n*multiplier + 0.5) / multiplier
def round_half_down(n, decimals=1):
multiplier = 10 ** decimals
return math.ceil(n*multiplier - 0.5) / multiplier
df['temp'] = df3['temp'].apply(lambda x: round_half_away_from_zero(x))
he float then updates and the whole column except three entries act like the supposed to: for example:
- 63.5 = 63.5
- 58.355 = 58.4
- 88.878 = 88.9
- 48.75 = 48.8
Strangely enough, only three entries dont work and they are:
- 67.75 = 67.7
- 58.25 = 58.2
- 46.65 = 46.6
If i just do the function on the single value it works, but not in the series, for example:
round_half_away_from_zero(67.5)
,
it works and gives 67.8, 58.3 and 46.7 respectively.
Any ideas, Thanks