从较大的时间间隔范围中减去较小的时间间隔

时间:2019-12-24 08:25:35

标签: python pandas time-series

enter image description here

import pandas as pd

start = pd.Timestamp('00:00:00')
end = pd.Timestamp('23:59:00')

# input
big_time_interval = pd.Interval(start, end)

smaller_time_intervals_to_subtract = [
    (pd.Timestamp('01:00:00'), pd.Timestamp('02:00:00')),
    (pd.Timestamp('16:00:00'), pd.Timestamp('17:00:00'))]


# output
_output_time_intervals = [
    (pd.Timestamp('00:00:00'), pd.Timestamp('01:00:00')),
    (pd.Timestamp('02:00:00'), pd.Timestamp('16:00:00')),
    (pd.Timestamp('17:00:00'), pd.Timestamp('23:59:00'))]

output_time_intervals = list(
    map(lambda interval: pd.Interval(*interval), _output_time_intervals))

任何帮助将不胜感激。

0 个答案:

没有答案