resamplig pandas (not as a timeseries)

2019-08-20 23:22发布

问题:

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 marvellously

With the Union, I add those indexes that I want but are not in the original df. Then I interpolate. Finally I filter only teh index I want.