Python 如何创建具有日期和时间间隔的np.sin()?

Python 如何创建具有日期和时间间隔的np.sin()?,python,pandas,numpy,Python,Pandas,Numpy,如何创建具有日期和时间间隔的np.sin() np.arange(0,100,0.1):创建数组时不返回错误 start = pd.Timestamp('2015-07-01') end = pd.Timestamp('2015-08-01') t = np.linspace(start.value, end.value, 100) time = pd.to_datetime(t) #time = np.arange(0, 100, 0.1) sin = np.sin(time) + np.r

如何创建具有日期和时间间隔的
np.sin()

np.arange(0,100,0.1)
:创建数组时不返回错误

start = pd.Timestamp('2015-07-01')
end = pd.Timestamp('2015-08-01')
t = np.linspace(start.value, end.value, 100)
time = pd.to_datetime(t)

#time = np.arange(0, 100, 0.1)
sin = np.sin(time) + np.random.normal(scale=0.5, size=len(time))
错误:

    sin = np.sin(time) + np.random.normal(scale=0.5, size=len(time))
TypeError: ufunc 'sin' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
打印时间:

    sin = np.sin(time) + np.random.normal(scale=0.5, size=len(time))
TypeError: ufunc 'sin' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
np_resource=np.dtype([(“resource”,np.ubyte,1)])DatetimeIndex([
'2015-07-01 00:00:00', '2015-07-01 07:30:54.545454592', '2015-07-01 15:01:49.090909184', '2015-07-01 22:32:43.636363520', “2015-07-02 06:03:38.181818112”


如果您基于时间创建时间序列,那么时间必须具有某种意义,因此您可以将其转换为弧度,然后应用sin函数。我建议使用基于秒时差的方法:

start = pd.Timestamp('2015-07-01')
end = pd.Timestamp('2015-08-01')
t = np.linspace(start.value, end.value, 100)
time = pd.to_datetime(t)

np.random.seed(0)
t = np.sin(np.radians((time - time.min()).seconds)) + \
    np.random.normal(scale=0.5, size=len(time))
一个情节是:


如果您要基于时间创建时间序列,那么时间必须具有某种意义,以便您可以将其转换为弧度,然后应用sin函数。我建议使用基于时间差(以秒为单位)的方法:

start = pd.Timestamp('2015-07-01')
end = pd.Timestamp('2015-08-01')
t = np.linspace(start.value, end.value, 100)
time = pd.to_datetime(t)

np.random.seed(0)
t = np.sin(np.radians((time - time.min()).seconds)) + \
    np.random.normal(scale=0.5, size=len(time))
一个情节是:


为什么我们需要datetime对象的sin?您期望的输出是什么?不必是datetime,只需要值​​是时间序列
np。sin
是角度的函数,以
弧度测量。它与时间或日期无关,为什么我们需要带datetime对象的sin?您期望的输出是什么?它不必是datetime,只需要值​​是时间序列
np。sin
是角度的函数,用
弧度测量。它与时间或日期无关,