Skip to content

Instantly share code, notes, and snippets.

@RenSys
Last active April 22, 2017 01:08
Show Gist options
  • Save RenSys/31e30661c4900e6c6f16aaf350cff32b to your computer and use it in GitHub Desktop.
Save RenSys/31e30661c4900e6c6f16aaf350cff32b to your computer and use it in GitHub Desktop.
Pandas - Create custom datetime range
import pandas as pd
from datetime import datetime
dd = 01
mm = 01
yyyy = 2011
pd.set_option('display.expand_frame_repr', False)
print '------ Day Shift ---------'
day_12_hrs_1hr_steps = pd.date_range(datetime(year=yyyy, month=mm, day=dd, hour=7),
periods=12, freq='H')
print day_12_hrs_1hr_steps
print '------ Night Shift ---------'
night_12_hrs_1hr_steps = pd.date_range(datetime(year=yyyy, month=mm, day=dd, hour=19),
periods=12, freq='H')
print night_12_hrs_1hr_steps
print '------ Night Shift , 2 hr increments ---------'
_24_hrs_2hr_steps = pd.date_range(
datetime(year=yyyy, month=mm, day=dd, hour=19), periods=12, freq='2H')
print _24_hrs_2hr_steps
# Frequence
# YearBegin, -> 'AS'
# YearEnd, -> 'A'
# BYearBegin, -> 'BAS'
# BYearEnd, -> 'BA'
# BusinessDay, -> 'B'
# BusinessMonthBegin, -> 'BMS'
# BusinessMonthEnd, -> 'BM'
# BQuarterEnd, -> 'BQ'
# BQuarterBegin, -> 'BQS'
# BusinessHour, -> 'BH'
# CustomBusinessDay, -> 'C'
# CustomBusinessMonthEnd, -> 'CBM'
# CustomBusinessMonthBegin, -> 'CBMS'
# CustomBusinessHour, -> 'CBH'
# MonthEnd, -> 'M'
# MonthBegin, -> 'MS'
# SemiMonthEnd, -> 'SM'
# SemiMonthBegin, -> 'SMS'
# Week, -> 'W'
# Second, -> 'S'
# Minute, -> 'T'
# Micro, -> 'U'
# QuarterEnd, -> 'Q'
# QuarterBegin, -> 'QS'
# Milli, -> 'L'
# Hour, -> 'H'
# Day, -> 'D'
# WeekOfMonth, -> 'WOM'
# FY5253
# FY5253Quarter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment