def _get_windowed_dataframe(time_series, segments, window_start, window_end):
    """For each segment, return a dataframe with the time relative to
    the start of the segment + window_offset.
    """
    for segment_start, segment_end in segments:
        if window_end is not None:
            segment_end = segment_start + window_end
        time_series_segment = time_series.loc[segment_start + window_start:
            segment_end, :]
        new_time = time_series_segment.index - segment_start
        yield time_series_segment.set_index(new_time)
