Trying to work with time but, typeerror: float() argument must be a string or a number
Trying to work with time but, typeerror: float() argument must be a string or a number
我有一个看起来像这样的数据集,它是我从 IEX 中提取的。日期是我将数据转换为数组后的时间戳,如下所示。
date close volume
0 2020-02-03 308.66 43496401
1 2020-02-04 318.85 34154134
2 2020-02-05 321.45 29706718
3 2020-02-06 325.21 26356385
[[Timestamp('2020-02-03 00:00:00') 308.66 43496401]
[Timestamp('2020-02-04 00:00:00') 318.85 34154134]
[Timestamp('2020-02-05 00:00:00') 321.45 29706718]
[Timestamp('2020-02-06 00:00:00') 325.21 26356385]]
下面是我的代码。
start = datetime(2020, 2, 1)
end = datetime(2020, 2, 27)
def get_price_vol(symbol):
get_info= get_historical_data(symbol, start, end, token='xyz',
close_only=True, output_format='pandas' )
return get_info
aapl_new = get_price_vol('aapl').reset_index()
x = np.array(aapl_new.drop(['prediction'],1))
x = x[:-forecasting_data]
print(x)
当我运行下面的代码时,我得到这个错误:
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_rbf.fit(x_train, y_train)
> TypeError: float() argument must be a string or a number, not 'Timestamp'
我看过并尝试过其他 Whosebug 答案,但 none 似乎有效。我想保留日期,但我需要将时间戳转换掉。对此的任何意见表示赞赏。谢谢!
如果要保留日期,应将它们转换为 UNIX 时间戳:
为此用途:
df.date = df.date.astype(int) / 10 ** 9
顺便问一下,为什么要将日期作为模型中的变量?我不建议这样做:您应该使用虚拟变量来跟踪季节性。
我有一个看起来像这样的数据集,它是我从 IEX 中提取的。日期是我将数据转换为数组后的时间戳,如下所示。
date close volume
0 2020-02-03 308.66 43496401
1 2020-02-04 318.85 34154134
2 2020-02-05 321.45 29706718
3 2020-02-06 325.21 26356385
[[Timestamp('2020-02-03 00:00:00') 308.66 43496401]
[Timestamp('2020-02-04 00:00:00') 318.85 34154134]
[Timestamp('2020-02-05 00:00:00') 321.45 29706718]
[Timestamp('2020-02-06 00:00:00') 325.21 26356385]]
下面是我的代码。
start = datetime(2020, 2, 1)
end = datetime(2020, 2, 27)
def get_price_vol(symbol):
get_info= get_historical_data(symbol, start, end, token='xyz',
close_only=True, output_format='pandas' )
return get_info
aapl_new = get_price_vol('aapl').reset_index()
x = np.array(aapl_new.drop(['prediction'],1))
x = x[:-forecasting_data]
print(x)
当我运行下面的代码时,我得到这个错误:
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_rbf.fit(x_train, y_train)
> TypeError: float() argument must be a string or a number, not 'Timestamp'
我看过并尝试过其他 Whosebug 答案,但 none 似乎有效。我想保留日期,但我需要将时间戳转换掉。对此的任何意见表示赞赏。谢谢!
如果要保留日期,应将它们转换为 UNIX 时间戳:
为此用途:
df.date = df.date.astype(int) / 10 ** 9
顺便问一下,为什么要将日期作为模型中的变量?我不建议这样做:您应该使用虚拟变量来跟踪季节性。