【问题标题】:convert yearly data to quarterly data将年度数据转换为季度数据
【发布时间】:2017-12-31 03:59:05
【问题描述】:

我有年度数据集想要转换为季度数据,通常我只想将年度值重复 4 次并将它们分配给当年的每个季度,谁能帮助我?谢谢。

【问题讨论】:

  • 这个问题没有足够的细节来产生好的答案。请看How to Ask

标签: python pandas


【解决方案1】:

您可以使用resampleffill

df = pd.DataFrame({'date':pd.date_range('2001-01-01',periods=15, freq='AS'),
                   'Value_1':np.random.randint(0,100,15)})

df=df.set_index('date')

df_out = df.resample('QS').ffill()

print(df_out.head(10))

输出:

            Value_1
date               
2001-01-01       87
2001-04-01       87
2001-07-01       87
2001-10-01       87
2002-01-01       37
2002-04-01       37
2002-07-01       37
2002-10-01       37
2003-01-01       11
2003-04-01       11

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 2021-03-08
    • 2023-03-31
    • 2015-12-22
    • 1970-01-01
    • 2020-08-28
    • 2016-11-16
    • 2020-08-14
    相关资源
    最近更新 更多