Is there a Python function to determine which quarter of the year a date is in?

后端 未结 14 1693
梦如初夏
梦如初夏 2020-11-29 00:07

Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?

14条回答
  •  孤街浪徒
    2020-11-29 00:26

    For those, who are looking for financial year quarter data, using pandas,

    import datetime
    import pandas as pd
    today_date = datetime.date.today()
    quarter = pd.PeriodIndex(today_date, freq='Q-MAR').strftime('Q%q')
    

    reference: pandas period index

提交回复
热议问题