I have large pandas dataframe (more than 1000000 rows) where I need to get in the fastest way possible the number of business days (excluding weekends) between two rows (n and n+1) where each contains a column date. And each time, I need to store the duration (outcome) in the row n of the same dataframe in a column called 'duration'. The result is in seconds.
I am using the below code to do the calculation in the fastest way I know about (any better way is welcomed ;-) ).
tmp_df['duration'] =
tmp_df['origin_tick_generation_time_stamp'].shift(-1) - tmp_df[
'origin_tick_generation_time_stamp']
I would like to calculate the duration without weekends in my code. I read that np.busday_count(date1, date2) will do exactly that. But do not know how to use it in my case. Is there a way to do it?
Many thanks