suppose I have a pandas.Series with index with numeric value type e.g.
pd.Series( [10,20], [1.1, 2.3] )
How do we resample above series with 0.1 interval? look like the .resample func only work on datetime interval?
That goes by the name of interpolation. You can think for resampling as a special case of interpolation.
In [24]: new_idx = s.index + pd.Index(np.arange(1.1, 2.3, .01))
In [25]: s.reindex(new_idx).interpolate().head()
Out[25]:
1.10 10.000000
1.11 10.083333
1.12 10.166667
1.13 10.250000
1.14 10.333333
dtype: float64
In [26]: s.reindex(new_idx).interpolate().tail()
Out[26]:
2.26 19.666667
2.27 19.750000
2.28 19.833333
2.29 19.916667
2.30 20.000000
dtype: float64
We need new_idx
to be a union of the original index and the values we want to interpolate, so that the original index isn't dropped.
Have a look at the interpolation methods: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.interpolate.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With