熊猫可能在多指标数据帧中插值缺失值。下面的示例不按预期方式工作:熊猫多指标数据帧,缺失值的ND插值
arr1=np.array(np.arange(1.,10.,1.))
arr2=np.array(np.arange(2.,20.,2.))
df1=pd.DataFrame(zip(arr1,arr2,arr1+arr2,arr1*arr2),columns=['x','y','xplusy','xtimesy'])
df1.set_index(['x','y'],inplace=True)
df2=df1.reindex(index=zip(*df1.index.levels)+[(2,2),(3,2),(5,5)])
df2.sortlevel([0,1],inplace=True)
df2.interpolate(method='linear',inplace=True)
显示不是我预期在xplusy和xtimesy列添加索引。
----------- ---- ---
(1.0, 2.0) 3 2
(2.0, 2.0) 4.5 5
(2.0, 4.0) 6 8
(3.0, 2.0) 7.5 13
(3.0, 6.0) 9 18
(4.0, 8.0) 12 32
(5.0, 5.0) 13.5 41
(5.0, 10.0) 15 50
(6.0, 12.0) 18 72
(7.0, 14.0) 21 98
(8.0, 16.0) 24 128
(9.0, 18.0) 27 162
----------- ---- ---
我正在寻找ND插值,如scipy中的griddata – denfromufa 2015-04-06 13:48:36
@denfromufa - 你应该将这个问题加入到这个问题中。我也会添加numpy作为标签(而不是数据框)。您可能需要从该问题中删除大熊猫内插,因为它看起来不会在这里有任何用处。当然只是建议。 – JohnE 2015-04-06 13:53:51
我在https://groups.google.com/forum/#!topic/pydata/ido98vCx86Q上发布了这个问题 – denfromufa 2015-04-06 14:35:16