admin 管理员组文章数量: 887021
解决:
问题描述:
原代码如下:
import pandas as pdfrom statsmodels.tsa.stattools import adfullerimport torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as Ffrom blitz.modules import BayesianLSTM
from blitz.utils import variational_estimatorfrom sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegressionimport matplotlib.pyplot as plt
%matplotlib inlinefrom collections import dequeimport yfinance as yf
import numpy as npplt.rcParams.update({'figure.figsize':(20,10)})
plt.rcParams.update({'font.size':20})
ticker = "SPY"
ticker_y = yf.Ticker("SPY")
df = ticker_y.history(period="5y")
然后出现报错:- SPY: No data found for this date range, symbol may be delisted
- SPY: No data found for this date range, symbol may be delisted
解决方案:
其实原因就在于这里使用的为Yahoo财经数据(从import yfinance as yf就可以证明这是Yahoo财经数据),但是由于现在使用Python访问不了那个网站了,所以可以自行寻找该网站的数据。使用read_csv等函数进行引用。
因此,解决方案为:
import pandas as pdfrom statsmodels.tsa.stattools import adfullerimport torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as Ffrom blitz.modules import BayesianLSTM
from blitz.utils import variational_estimatorfrom sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegressionimport matplotlib.pyplot as plt
%matplotlib inlinefrom collections import dequeimport yfinance as yf
import numpy as npplt.rcParams.update({'figure.figsize':(20,10)})
plt.rcParams.update({'font.size':20})
df_non_stat = pd.read_csv("stock_train.csv", index_col = 0, parse_dates=[0])
df_non_stat
输出结果:
如果想要测试代码,自己可以按照上述字段来,这就是使用的格式了
本文标签: 解决
版权声明:本文标题:解决: 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1731236381h1475934.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论