I have a solved question update column values based on length temp dataframes based on source dataframe
there is a code:
import pandas as pd
df = pd.DataFrame({
'ID': ['aaa', 'aaa', 'aaa', 'bbb', 'ccc', 'ccc'],
'closed': ['2023-03-28 22:00', '2023-03-28 22:00', '2023-03-28 22:00', '2023-03-29 23:00', '2023-03-27 22:00', '2023-03-27 22:00'],
'set': ['2023-03-27 19:00', '2023-03-28 19:30', '2023-03-28 20:00', '2023-03-27 22:00', '2023-03-25 19:00', '2023-03-26 19:30'],
'message_time': ['19:05', '19:40', '21:00', '22:10', '19:05', '19:40']
})
df['newtime'] = (s.groupby(df['ID']).diff(-1).mul(-1)
.fillna(c-s)
.dt.total_seconds().div(60)
)
output is differnce in minutes (fillna(c-s)
).
I need to replace this with business minutes.
I tried but it didn't work.
For example, create new column simply using module business_duration:
import holidays as pyholidays
from datetime import time, datetime
holidaylist_RU = pyholidays.Russia(years=[datetime.now().year, datetime.now().year-1])
start_hour = time(10, 0, 0)
end_hour = time(21, 0, 0)
unit_min='min'
DATA_REACTION['reaction (minutes)'] = DATA_REACTION.apply(lambda x: bd.businessDuration(datetime.strptime(x['start'], '%Y-%m-%d %H:%M:%S'), datetime.strptime(x['end'], '%Y-%m-%d %H:%M:%S'), start_hour, end_hour, holidaylist=holidaylist_RU, unit=unit_min), axis=1)
It works for direct applying.
How implement this solution to fillna
row?