熊貓可能在多指標數據幀中插值缺失值。下面的示例不按預期方式工作:熊貓多指標數據幀,缺失值的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