Could you please resolve this tackle? I would like to calculate a diff of time (business time) between 2 columns of DataFrame however I get an error sth like this: 'Series' object has no attribute 'tzinfo'.
import datetime
import pytz
import businesstimedelta
#workday definition
workday = businesstimedelta.WorkDayRule(
start_time=datetime.time(6),
end_time=datetime.time(18),
working_days=[0, 1, 2, 3, 4])
businesshrs = businesstimedelta.Rules([workday])
#Calculate the business time between two datetimes
start = df_dur["startdate"]
end = df_dur["enddate"]
bdiff = businesshrs.difference(start, end)
print(bdiff)
CodePudding user response:
Use DataFrame.apply
:
df['bdiff'] = df.apply(lambda x: businesshrs.difference(x["startdate"],x["enddate"]),axis=1)