0

We have Pandas dataframe with start_date and end_date columns(Input format is given below). I need to check whether the given input time range is present between the start_date and end_date.

For example, if the time range is 09:30-10:30, the output should be first row (student1) and if time range is 16:00-17:30, the output should be second row (student2). Please guide me how can I achieve this.

Input Dataframe:

        name          start_date            end_date
0   student1    2020-08-30 09:00:00     2020-08-30 10:00:00
1   student2    2020-08-30 15:00:00     2020-08-30 18:00:00
2   student3    2020-08-30 11:00:00     2020-08-30 12:30:00

1 Answer 1

1

Supposing your date columns are datetime format:

from datetime import datetime
start_time = datetime(2020, 1, 1, 9, 30)
end_time = datetime(2020, 1, 1, 10, 30)

df['start_date'].dt.time.le(end_time.time())&df['end_date'].dt.time.ge(start_time.time())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.