我有一个文件,每天有83个气象站的降水数据,每个站101年。我想确定每个电台每年NaN的数量。在Python中填写缺失的行为NaN
作为一个缩短的例子,假设我只有一个站和只关心约1年的数据,2009年
如果我有这样的:
station_id year month 1 2 3
210018 2009 1 5 6 8
210018 2009 2 NaN NaN 6
210018 2009 12 8 5 6
我想这样的:
station_id year month 1 2 3
210018 2009 1 5 6 8
210018 2009 2 NaN NaN 6
210018 2009 3 NaN NaN NaN
210018 2009 4 NaN NaN NaN
210018 2009 5 NaN NaN NaN
210018 2009 6 NaN NaN NaN
210018 2009 7 NaN NaN NaN
210018 2009 8 NaN NaN NaN
210018 2009 9 NaN NaN NaN
210018 2009 10 NaN NaN NaN
210018 2009 11 NaN NaN NaN
210018 2009 12 8 5 6
所以我的车站需要12行12个月和一年一起去每一个。我再次以真实的例子展现101年。
我想使用此代码:
df_indexed=df.set_index(['year'])
new_index=np.arange(1910,2011,1)
idx=pd.Index(new_index)
df2=df_indexed.reindex(idx, method=None)
但它返回一个长的错误与
ValueError: cannot reindex from a duplicate axis
我希望是有道理的结束。
非常感谢! – spotter 2015-02-23 21:15:30