将年度数据转换为季度d

2024-04-18 20:04:52 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 数据年度季度
1条回答
网友
1楼 · 发布于 2024-04-18 20:04:52

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

输出:

^{pr2}$

相关问题 更多 >