将年度数据转换为季度数据

时间:2017-12-31 03:59:06

标签: python pandas

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

1 个答案:

答案 0 :(得分:0)

您可以使用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