pandas.Period.strftime#
- Period.strftime()#
Returns a formatted string representation of the
Period.fmtmust beNoneor a string containing one or several directives. WhenNone, the format will be determined from the frequency of the Period. The method recognizes the same directives as thetime.strftime()function of the standard Python distribution, as well as the specific additional directives%f,%F,%q,%l,%u,%n. (formatting & docs originally from scikits.timeries).Directive
Meaning
Notes
%aLocale’s abbreviated weekday name.
%ALocale’s full weekday name.
%bLocale’s abbreviated month name.
%BLocale’s full month name.
%cLocale’s appropriate date and time representation.
%dDay of the month as a decimal number [01,31].
%f‘Fiscal’ year without a century as a decimal number [00,99]
(1)
%F‘Fiscal’ year with a century as a decimal number
(2)
%HHour (24-hour clock) as a decimal number [00,23].
%IHour (12-hour clock) as a decimal number [01,12].
%jDay of the year as a decimal number [001,366].
%mMonth as a decimal number [01,12].
%MMinute as a decimal number [00,59].
%pLocale’s equivalent of either AM or PM.
(3)
%qQuarter as a decimal number [1,4]
%SSecond as a decimal number [00,61].
(4)
%lMillisecond as a decimal number [000,999].
%uMicrosecond as a decimal number [000000,999999].
%nNanosecond as a decimal number [000000000,999999999].
%UWeek number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.
(5)
%wWeekday as a decimal number [0(Sunday),6].
%WWeek number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.
(5)
%xLocale’s appropriate date representation.
%XLocale’s appropriate time representation.
%yYear without century as a decimal number [00,99].
%YYear with century as a decimal number.
%ZTime zone name (no characters if no time zone exists).
%%A literal
'%'character.Notes
The
%fdirective is the same as%yif the frequency is not quarterly. Otherwise, it corresponds to the ‘fiscal’ year, as defined by theqyearattribute.The
%Fdirective is the same as%Yif the frequency is not quarterly. Otherwise, it corresponds to the ‘fiscal’ year, as defined by theqyearattribute.The
%pdirective only affects the output hour field if the%Idirective is used to parse the hour.The range really is
0to61; this accounts for leap seconds and the (very rare) double leap seconds.The
%Uand%Wdirectives are only used in calculations when the day of the week and the year are specified.
Examples
>>> from pandas import Period >>> a = Period(freq='Q-JUL', year=2006, quarter=1) >>> a.strftime('%F-Q%q') '2006-Q1' >>> # Output the last month in the quarter of this date >>> a.strftime('%b-%Y') 'Oct-2005' >>> >>> a = Period(freq='D', year=2001, month=1, day=1) >>> a.strftime('%d-%b-%Y') '01-Jan-2001' >>> a.strftime('%b. %d, %Y was a %A') 'Jan. 01, 2001 was a Monday'