'Pandas get subtract of value between hours

I have DataFrame:

date, time, value
2019-06-03, 15:30:00, 5131
2019-06-03, 15:45:00, 5142
2019-06-03, 16:00:00, 5135
2019-06-04, 15:30:00, 5134
2019-06-04, 15:45:00, 5138
2019-06-04, 16:00:00, 5148

i need data like: how many dates is on plus/minus(value) between time like [15:30:00-16:00:00], iterate by all possible hours

output example: [15:30:00 - 16:00:00] 2 rows on plus // because 1st date: 5135-5131=4 / 2nd date 5148-5134=14



Solution 1:[1]

You could convert your dates in seconds and then do

import pandas as pd

df = pd.DataFrame(yourData)
start = df["Seconds"] >= lowerSeconds
end = df["Seconds"] <= upperSeconds
dates_between_start_and_end = df[start & end]
# => all Values are Nan. except those in range of [lowerSeconds, upperSeconds]

I could imagine that there is a way to do the same claculation with Date objects

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1