It is straightforward to create a Period
object for the current basic unit of time, such as second, minute, hour, day, week, month, quarter, or year:
>>> pd.Period.now("T")
Period('2023-06-29 12:34', 'T')
>>> pd.Period.now("D")
Period('2023-06-29', 'D')
>>> pd.Period.now("M")
Period('2023-06', 'M')
However if I want to get the current 15-minutes period (quarter hour),
>>> pd.Period.now("15T")
Period('2023-06-29 12:34', '15T')
it does not start at :00
, :15
, :30
, or :45
. It starts at the current minute.
The most compact piece of code, that does the job is:
>>> pd.Timestamp.now().floor("15T").to_period("15T")
Period('2023-06-29 12:30', '15T')
Is there anything more compact? Especially without having to mention "15T"
twice?