2

here are two really useful questions for datetime comparison in python:

Calculate Pandas DataFrame Time Difference Between Two Columns in Hours and Minutes

Determine the difference between two DateTimes, only counting opening hours

I have a dataframe in python with two columns:

A                      B
10:00:00 01.01.2019    12:00:00 02.01.2019

And I have opening hours (which are relevant hours), which only should count for the calculation, so not the full 24 hours and maybe not every day. So my business would be open from: 10:00:00 - 18:00:00 every day, how can i adjust:

df_time['td'] = df_time['B']-df_time['A']  

That the outcome would be 10 hours in this case? And it is open from monday to friday.

PV8
  • 5,799
  • 7
  • 43
  • 87

1 Answers1

1

Not a full answer, but I would do:

  1. Count the time in the first day 18:00:00 - df['A'].dt.time
  2. Count the time in the last day df['B'] - 10:00:00
  3. Count the day in between and multiply by 8.
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74