Reputation: 1511
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
Upvotes: 0
Views: 1172
Reputation: 1511
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.
Upvotes: 1