У меня есть следующие данные.
date value
2018-06-04 191.790000
2016-05-13 87.454124
2015-11-06 115.626664
2015-08-21 100.580815
2015-05-22 125.482610
2013-12-27 73.598623
2013-04-19 50.347372
2012-09-21 89.324522
2011-11-25 46.190391
2011-06-17 40.687995
2010-08-27 30.697038
2010-06-18 34.820214
2009-01-16 10.459760
2007-12-28 25.387754
2006-07-14 6.437459
2006-01-13 10.873919
2005-02-25 5.652946
2004-06-25 2.140738
2003-12-19 1.251411
Типы данных:
In: high_low.info()
Out:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 19 entries, 2018-06-04 to 2003-12-19
Data columns (total 1 columns):
value 19 non-null float64
dtypes: float64(1)
memory usage: 944.0 bytes
Я хотел бы использовать сплайн-интерполяцию, используя:
x = high_low.index
y = high_low['value']
interp1d(x, y, kind='cubic')
но если я пытаюсь запустить его, он выдает следующее сообщение об ошибке:
> --> 512 if np.isnan(self.x).any():
>
> TypeError: ufunc 'isnan' not supported for the input types, and the
> inputs could not be safely coerced to any supported types according to
> the casting rule ''safe''
У кого-нибудь есть идея, чтобы исправить эту проблему?Заранее спасибо.
edit: Как предложил К.Р.Киров, я попытался преобразовать тип данных из datetime64 [ns] в float, добавив:
In: high_low.index.values.astype('d')
Out: array([1.5280704e+18, 1.4630976e+18, 1.4467680e+18, 1.4401152e+18,
1.4322528e+18, 1.3881024e+18, 1.3663296e+18, 1.3481856e+18,
1.3221792e+18, 1.3082688e+18, 1.2828672e+18, 1.2768192e+18,
1.2320640e+18, 1.1988000e+18, 1.1528352e+18, 1.1371104e+18,
1.1092896e+18, 1.0881216e+18, 1.0717920e+18])
Путем построения графиков значений:
f2 = interp1d(x, y, kind='cubic')
x = high_low.index.values.astype('d')
y = high_low['value']
plt.plot(x,f2(x),color='green')
scatter(high_low.index.values.astype('d'),high_low['value'],color='red')
Я получил:
сплайн
У кого-нибудь есть лучший способ вернуть ось x к исходному типу datetimeindex?