def period(row):
    visit_start = {'hour': row.first_seen.hour, 'min': row.first_seen.minute}
visit_end = {'hour': row.last_seen.hour, 'min': row.last_seen.minute}
for period_start, label in list(periods.items()):
    period_end = period_start + 4
if period_start <= visit_start['hour'] < period_end:
    if period_start <= visit_end['hour'] < period_end or (period_end -
        visit_start['hour']) * 60 - visit_start['min'] > (visit_end['hour'] -
        period_end) * 60 + visit_end['min']:
        return label
else:
    return periods[period_end]
Добавление нового столбца во фрейм данных после своевременного расчета