You are performing the rounding operation passing a series as an argument. Instead you need to fix this to perform the rounding up for each value in the series. I suggest you use map with a lambda in the function to do it:

Data['Numerator'] = Data['Numerator'].map(lambda x: Decimal(x).quantize(Decimal('.1'), rounding=ROUND_HALF_UP))

The output we get is as expected:

  Code Disaggregation Numerator
0    x              a      19.3
1    x              b      82.1
2    x          Total     101.2
Answer from Celius Stingher on Stack Overflow
Top answer
1 of 2
2

timestamps

You need to use dt.round. This is however a bit as the previous/next hour behavior depends on the hour itself. You can force it by adding or subtracting a small amount of time (here 1ns):

s = pd.to_datetime(pd.Series(['1/2/2021 3:45', '25/4/2021 12:30', 
                              '25/4/2021 13:30', '12/4/2022 23:45']))

# xx:30 -> rounding depending on the hour parity (default)
s.dt.round(freq='1h')

0   2021-01-02 04:00:00
1   2021-04-25 12:00:00    <- -30min
2   2021-04-25 14:00:00    <- +30min
3   2022-12-05 00:00:00
dtype: datetime64[ns]


# 00:30 -> 00:00 (force down)
s.sub(pd.Timedelta('1ns')).dt.round(freq='1h')

0   2021-01-02 04:00:00
1   2021-04-25 12:00:00
2   2021-04-25 13:00:00
3   2022-12-05 00:00:00
dtype: datetime64[ns]


# 00:30 -> 01:00 (force up)
s.add(pd.Timedelta('1ns')).dt.round(freq='1h')

0   2021-01-02 04:00:00
1   2021-04-25 12:00:00
2   2021-04-25 13:00:00
3   2022-12-05 00:00:00
dtype: datetime64[ns]

floats

IIUC, you can use divmod (or numpy.modf) to get the integer and decimal part, then perform simple boolean arithmetic:

s = pd.Series([7.15, 5.25, 22.30, 18.45])

s2, r = s.divmod(1)  # or np.modf(s)

s2[r.ge(0.3)] += 1

s2 = s2.astype(int)

Alternative: using mod and boolean to int equivalence:

s2 = s.astype(int)+s.mod(1).ge(0.3)

output:

0     7
1     5
2    23
3    19
dtype: int64

Note on precision. It is not always easy to compare floats due to floating point arithmetics. For instance using gt would fail on the 22.30 here. To ensure precision round to 2 digits first.

s.mod(1).round(2).ge(0.3)

or use integers:

s.mod(1).mul(100).astype(int).ge(30)
2 of 2
1

Here a version that works with timestamps:

#dummy data:
df = pd.DataFrame({'time':pd.to_datetime([np.random.randint(0,10**8) for a in range(10)], unit='s')})


def custom_round(df, col, out):
    if df[col].minute >= 30:
        df[out] = df[col].ceil('H')
    else:
        df[out] = df[col].floor('H')
    return df


df.apply(lambda x: custom_round(x, 'time', 'new_time'), axis=1)

#edit:

using numpy:

def custom_round(df, col, out):
    df[out] = np.where(
        (
            df['time'].dt.minute>=30), 
            df[col].dt.ceil('H'), 
            df[col].dt.floor('H')
    )
    return df
df = custom_round(df, 'time', 'new_time')
Discussions

dataframe - Rounding Python Values to the Nearest Half Number - Stack Overflow
I'm struggling with a few things right now using python dataframes. I have one column with a long list of numbers ranging from 1-5. For example, the column contains the values (3.6, 2.1, 4.7, 3.8, ... More on stackoverflow.com
🌐 stackoverflow.com
python - Python3 pandas dataframe round .5 always up - Stack Overflow
I want to round values in my pandas.DataFrame such that 0.5 is always rounded up. A way to fix it would be to use the decimal module with Decimal datatype as described here: How to properly round up half float numbers in Python? More on stackoverflow.com
🌐 stackoverflow.com
python - Rounding half away from zero on entire pandas dataframe - Stack Overflow
I am struggling with trying to get a standard round on a pandas dataframe. I am aware that the round() function doesn't behave as one would expect by design. Can I please get some help on how to More on stackoverflow.com
🌐 stackoverflow.com
[pandas] How to round up to the nearest 0.5?
import numpy as np df['volume_round_up'] = np.ceil(df['volume'] * 2) / 2 df['map'] = df['volume_round_up'].map(di) or in one shot: df['map'] = (np.ceil(df['volume'] * 2) / 2).map(di) More on reddit.com
🌐 r/learnpython
10
11
January 5, 2022
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Round, floor, and ceil for DataFrame and Series | note.nkmk.me
January 15, 2024 - The round() method in pandas uses bankers' rounding, which means it rounds half to even. For example, 0.5 and 2.5 are rounded to 0.0 and 2.0, respectively.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.round.html
pandas.DataFrame.round — pandas 3.0.2 documentation
For values exactly halfway between rounded decimal values, pandas rounds to the nearest even value (e.g.
🌐
Runebook.dev
runebook.dev › en › docs › pandas › reference › api › pandas.dataframe.round
Precision in pandas: Common DataFrame.round() Pitfalls and NumPy Solutions
import pandas as pd import numpy ... = 10**decimals return np.floor(series * factor + 0.5) / factor df['Round_Half_Up'] = round_half_up(df['Value'], decimals=0) print("DataFrame with 'Round Half Up' Rounding:\n", df) # Result: ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.round.html
pandas.Series.round — pandas 3.0.2 documentation - PyData |
For values exactly halfway between rounded decimal values, pandas rounds to the nearest even value (e.g.
🌐
Data to Fish
datatofish.com › round-values-pandas-dataframe
How to Round Values in a pandas DataFrame
import pandas as pd data = {'fish': ['salmon', 'pufferfish', 'shark'], 'length_m': [1.523, 0.2165, 2.1], 'width_cm': [10.2, 3.14159, 90.0] } df = pd.DataFrame(data) df = df.round(2) print(df) fish length_m width_cm 0 salmon 1.52 10.20 1 pufferfish 0.22 3.14 2 shark 2.10 90.00 · That's it! You just rounded values in a DataFrame. On this page · Example 1: Round Values in a Column ·
Find elsewhere
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - Python’s built-in round() function uses the rounding half to even strategy, which rounds numbers like 2.5 to 2 and 3.5 to 4. This method helps minimize rounding bias in datasets. To round numbers to specific decimal places, you can use the round() function with a second argument specifying the number of decimals. For more advanced rounding strategies, you can explore Python’s decimal module or use NumPy and pandas for data science applications.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-round-a-float-in-pandas
Pandas round() Method – How To Round a Float in Pandas
March 13, 2023 - The number of decimal places to be returned is passed in as a parameter. round(2) return rounds a number to two decimal places. ... import pandas as pd data = {'cost':[20.5550, 21.03535, 19.67373, 18.233233]} df = pd.DataFrame(data) ...
🌐
Stack Overflow
stackoverflow.com › questions › 67212136 › rounding-half-away-from-zero-on-entire-pandas-dataframe
python - Rounding half away from zero on entire pandas dataframe - Stack Overflow
def round_adjusted(n, decimals=0): ... y is positive, and q = y − 0.5 if y is negative. For example, 23.5 gets rounded to 24, and −23.5 gets rounded to −24....
🌐
Reddit
reddit.com › r/learnpython › [pandas] how to round up to the nearest 0.5?
r/learnpython on Reddit: [pandas] How to round up to the nearest 0.5?
January 5, 2022 -

I have a dataframe df:

df = pd.DataFrame({"volume": [0.3300, 5.600, 64.0915, 1.730000, 4.123000]})
volume
0.3300
5.600
64.0915
1.730000
4.123000

I also have a non-exhausting dict di:

di = {
    0.5: 6.26,
    1.0: 6.28,
    1.5: 6.36,
    2.0: 6.46,
    2.5: 6.56,
    3.0: 6.66,
    3.5: 6.76,
    4.0: 6.86,
    4.5: 6.96,
    5.0: 6.98,
    5.5: 7.15
    ...
}

I need to create a new column ["map"] where I map di to df["volume"].

df["map"] = df["volume"].map(di)

but for that I need to round up each number in df["volume"] to the next 0.5, so the values should look like:

volume volume_round_up
0.3300 0.5
5.600 6.0
64.0915 64.5
1.730000 2.0
4.123000 4.5

How can I do this in a vectorized way?

🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › round
Python Pandas DataFrame round() - Round Numeric Values | Vultr Docs
December 24, 2024 - This example calculates the sum of column 'A' before and after rounding to illustrate how numerical operations might differ due to rounding. Such discrepancies can be significant depending on the data and the required precision for analysis or reporting. Integrate NumPy for more complex rounding rules like rounding towards zero, ceil, or floor. Employ the combination of pandas ...
🌐
W3Schools
w3schools.com › python › pandas › ref_df_round.asp
Pandas DataFrame round() Method
import pandas as pd data = [[1.1235, 1.9654, 2.6874], [6.5124, 4.2210, 2.2899]] df = pd.DataFrame(data) print(df.round(1)) Try it Yourself »
🌐
Educative
educative.io › answers › how-to-round-up-a-dataframe-in-pandas
How to round up a DataFrame in pandas
Line 4: We import the pandas library. Lines 7–8: We create a DataFrame, df. Line 10: We print the DataFrame, df. Line 13: We round the values of the DataFrame to 2 decimal places.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pandas-dataframe-round
Pandas DataFrame round() Method | Round Values to Decimal - GeeksforGeeks
import pandas as pd df = pd.DataFrame({ "A": [1.2345, 2.3456], "B": [3.4567, 4.5678] }) print(df.round(2)) ... Explanation: df.round(2) rounds all numeric values in the DataFrame to 2 decimal places.
Published   January 13, 2026
🌐
Trymito
trymito.io › excel-to-python › functions › math › ROUND
Excel to Python: ROUND Function - A Complete Guide | Mito
By default, pandas uses the 'round half to even' method, often referred to as 'bankers' rounding'. This might differ from the expected behavior in Excel which rounds 0.5 always up.
🌐
Skytowner
skytowner.com › explore › pandas_dataframe_round_method
Pandas DataFrame | round method with Examples
Method absMethod clipMethod corrMethod corrwithMethod countMethod covMethod cummaxMethod cumminMethod cumprodMethod cumsumMethod describeMethod diffMethod evalMethod madMethod maxMethod meanMethod medianMethod minMethod modeMethod nuniqueMethod pct_changeMethod productMethod quantileMethod rankMethod roundMethod semMethod stdMethod sumMethod var ... ParametersReturn ValueExamplesRounding all values to nearest integerRounding all values to the nearest 10thRounding all values to the 1st decimal placeRounding certain columns onlyPassing in DictPassing in Series mode_heat · Master the mathematics behind data science with 100+ top-tier guides Start your free 7-days trial now! Pandas DataFrame.round(~) method returns a DataFrame with all its numerical values rounded according to the specified parameters.