1

Let's start with two dates, two days apart, resample daily, and interpolate:

In [1]: ts = pd.Series([1, 2], index=pd.DatetimeIndex(['1950-01-01', '1950-01-03']))

In [2]: ts.resample('D').interpolate()
Out[2]:
1950-01-01    1.0
1950-01-02    1.5
1950-01-03    2.0
Freq: D, dtype: float64

So far so good. Next, let's try doing it with two dates two years apart, and resample yearly:

In [3]: ts = pd.Series([1, 2], index=pd.DatetimeIndex(['1950-01-01', '1952-01-01']))

In [4]: ts.resample('Y').interpolate()
Out[4]:
1950-12-31   NaN
1951-12-31   NaN
1952-12-31   NaN
Freq: A-DEC, dtype: float64

Why do I get NaNs instead of [1., 1.5, 2.]?

ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65

1 Answers1

3

Use the appropriate rule:

ts.resample('AS').interpolate()

or

ts.resample('YS').interpolate()

where 'AS' and 'YS' correspond to the start of the year.

BigBen
  • 46,229
  • 7
  • 24
  • 40