Reputation: 553
I am calculating the time worked for the operators, there is a format table:
operator, call accepted like this
In the cycle I subtract 2-1, 3-2, etc and summarize in variable Time.
if CurrentOperator == list.iloc[i][0]:
DiffTime = list.iloc[i][1] - list.iloc[i-1][1]
if DiffTime > pd.Timedelta('46 minutes'):
DiffTime = pd.Timedelta('0 minutes')
Time += DiffTime
else:
How can I round time to nearest hour? If variable Time have type timedeltas.Timedelta
Upvotes: 0
Views: 414
Reputation: 36624
You can use pandas.Timedelta.round(self, freq)
from pandas import Timedelta
time = Timedelta('09:55:49')
print(time)
Out[5]: Timedelta('0 days 09:55:49')
Timedelta.round(time, 'h')
Out[6]: Timedelta('0 days 10:00:00')
Upvotes: 2