resamplig pandas (not as a timeseries)

倖福魔咒の 提交于 2019-12-13 03:46:08

问题


I have a pandas dataframe like this:

index x y 0.010 1 Nan 0.011 Nan 3 0.014 NaN 4 0.019 9 Nan 0.020 10 7

This matrix comes from a concatenation of 2 matrices I would like to resample the index at equally spaced intervals, say 0.010, 0.012,0.014..... 0.020, filling the NaN with linear interpolation. Similar to what resample does if index were a time series...

Can anyone send me hints? I am having an headache with this Thanks you


回答1:


Solved!

df1 = A.reindex(A.index.union(np.linspace(0.0,0.1,11)))
df1.interpolate('index').loc[np.linspace(0.0,1.1,11)]

This does the trick marvelously.

With the union, I add the indexes that I want that do not appear in the original dataframe.

Then I interpolate and use loc to filter only the indexes that I want.



来源:https://stackoverflow.com/questions/48697906/resamplig-pandas-not-as-a-timeseries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!