当向上舍入的条件取决于另一列中的值时,如何舍入一列中的值?蟒蛇

我是Python的初学者。我有一个Pandas数据框df,如下所示。

     id            time       category
     1             5.85          20
     1             5.85          20
     1             5.85          20
     1             6.50          20
     2             6.33          30
     2             6.50          30
     2             5.85          30
     3             6.33          20
     4             15.00         30
     4             16.50         30 

我想编写一个针对每个id的函数,当累积总和大于“类别”列中的值时,将“时间”列中的值四舍五入到最接近的整数,而不打印累积总和。因此,当我将函数应用于数据框时,我希望df如下所示

      id           time       category
      1             5.85          20
      1             5.85          20
      1             5.85          20
      1             7             20
      1             7             20
      2             6.50          30
      2             5.85          30
      3             6.33          20
      4             15.00         30
      4             17            30

I've written several functions in Python including loops and other builtin functions, but each time had different errors. My main inspiration was the post in the following link (Find (only) the first row satisfying a given condition in pandas DataFrame). But somehow I keep getting lost. Very much appreciated if anyone can help!