【问题标题】:Pandas DataFrame - Generate Semi-annual Period IndexPandas DataFrame - 生成半年期指数
【发布时间】:2021-12-26 15:13:24
【问题描述】:

目前,我可以通过在以下代码中更改频率来生成季度、月度和年度索引。

df['period_index'] = pd.PeriodIndex(df.Date, freq='Q')

有没有办法调整freq 并获得半年度指数?

【问题讨论】:

    标签: python-3.x pandas dataframe datetime period


    【解决方案1】:

    如果您先使用date_range,则有一些变通方法:

    pd.PeriodIndex(pd.date_range(df.Date.min(), df.Date.max(), freq="6M"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      • 2018-09-04
      • 2022-06-18
      • 2022-08-19
      • 2020-07-31
      相关资源
      最近更新 更多