将每日平均值广播到不同年份

问题描述

我希望将一年内的每日平均值(365 个值)广播到不同年份,以便特定日期在不同年份(包括闰年)中具有相同的值。我可以使用“reindex”、“ffill”和“bfill”轻松完成月度数据,但每日数据一直在获得 NaN。下面是示例代码:

import pandas as pd
import datetime as dt
import numpy as np

julians  = np.arange(1,366,1)
date_str = [dt.datetime.strptime(str(days).zfill(3),'%j').date() for days in julians]

date_ind = [strs.strftime('%m-%d') for strs in date_str]
dfs =pd.DataFrame(np.arange(1,1),index = date_ind)

dfs_ref = pd.DataFrame(np.arange(1,1462,1 ),index = pd.date_range('2015-01-01','2018-12-31',freq = 'D'))  # the reference index

df_fin = dfs.reindex(dfs_ref.index).ffill() #df_fin = dfs.reindex(dfs_ref.index).bfill() # neither works,I get all NaNs

谁能帮我解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...