pandas.tseries.offset, 获取季度,月度第一天(最后一天)

Class name Description
DateOffset Generic offset class, defaults to 1 calendar day
BDay business day (weekday)
CDay 这个可以设置特定的假期
Week one week, optionally anchored on a day of the week
WeekOfMonth the x-th day of the y-th week of each month
LastWeekOfMonth the x-th day of the last week of each month
MonthEnd calendar month end
MonthBegin calendar month begin
BMonthEnd business month end
BMonthBegin business month begin
CBMonthEnd custom business month end
CBMonthBegin custom business month begin
SemiMonthEnd 15th (or other day_of_month) and calendar month end
SemiMonthBegin 15th (or other day_of_month) and calendar month begin
QuarterEnd calendar quarter end
QuarterBegin calendar quarter begin
BQuarterEnd business quarter end
BQuarterBegin business quarter begin
FY5253Quarter retail (aka 52-53 week) quarter
YearEnd calendar year end
YearBegin calendar year begin
BYearEnd business year end
BYearBegin business year begin
FY5253 retail (aka 52-53 week) year
BusinessHour 可以自己设置工作时间
CustomBusinessHour custom business hour
Hour one hour
Minute one minute
Second one second
Milli one millisecond
Micro one microsecond
Nano one nanosecond

 

from pandas.tseries.offsets import *
from datetime import datetime
a = datetime.today()
a
Out[25]: datetime.datetime(2019, 4, 4, 13, 57, 44, 141188)
a + QuarterEnd()
Out[26]: Timestamp('2019-06-30 13:57:44.141188')
a + QuarterBegin()
Out[27]: Timestamp('2019-06-01 13:57:44.141188')
a - QuarterBegin()
Out[28]: Timestamp('2019-03-01 13:57:44.141188')


a - BQuarterBegin()
Out[35]: Timestamp('2019-03-01 13:57:44.141188')
a - BQuarterEnd()
Out[36]: Timestamp('2019-03-29 13:57:44.141188')
a + BQuarterEnd()
Out[37]: Timestamp('2019-06-28 13:57:44.141188')
a + 2*BQuarterEnd()
Out[38]: Timestamp('2019-09-30 13:57:44.141188')
a + YearEnd()
Out[39]: Timestamp('2019-12-31 13:57:44.141188')
a + 2*YearEnd()
Out[40]: Timestamp('2020-12-31 13:57:44.141188')

 

你可能感兴趣的:(Pandas,Python)