我跑
import yfinance as yf
df = yf.Ticker("NOK").history(start_date="2020-11-30", end_date="2021-09-30", interval="1h")回传
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-15-c5289e094c7b> in <module>
1 import yfinance as yf
2
----> 3 df = yf.Ticker("NOK").history(start_date="2020-11-30", end_date="2021-09-30", interval="1h")
D:\Programme\Python\Anaconda\lib\site-packages\yfinance\base.py in history(self, period, interval, start, end, prepost, actions, auto_adjust, back_adjust, proxy, rounding, tz, **kwargs)
155 # Every valid ticker has a timezone. Missing = problem
156 shared._DFS[self.ticker] = utils.empty_df()
--> 157 shared._ERRORS[self.ticker] = err_msg
158 if "many" not in kwargs and debug_mode:
159 print('- %s: %s' % (self.ticker, err_msg))
D:\Programme\Python\Anaconda\lib\site-packages\requests\models.py in json(self, **kwargs)
896 if self.status_code == 0 or self.raw is None:
897 self._content = None
--> 898 else:
899 self._content = b"".join(self.iter_content(CONTENT_CHUNK_SIZE)) or b""
900
D:\Programme\Python\Anaconda\lib\json\__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
355 parse_int is None and parse_float is None and
356 parse_constant is None and object_pairs_hook is None and not kw):
--> 357 return _default_decoder.decode(s)
358 if cls is None:
359 cls = JSONDecoder
D:\Programme\Python\Anaconda\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
D:\Programme\Python\Anaconda\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)我尝试用以下代码更新库,这些代码来自于这里的另一个问题:
pip安装yfinance -升级-无缓存-dir
此外,我担心没有这类每小时的数据。但这没什么改变。你能帮帮我吗?
发布于 2022-11-11 17:46:42
我认为在安装yfinance模块时出现了错误。
下面的行为ubuntu20.04安装了一个带有yfinance的虚拟环境。(如果你是在做其他的事情,请告诉我,只是细微的差别)
python3 -m venv venv
source venv/bin/activate
pip install yfinance在此之后,使用以下python代码:
import yfinance as yf
print(yf.Ticker("NOK").history(start_date="2020-11-30", end_date="2021-09-30", interval="1h"))打印出来:
Open High ... Dividends Stock Splits
2022-10-11 12:30:00-04:00 4.3800 4.400 ... 0.0 0
2022-10-11 13:30:00-04:00 4.3700 4.380 ... 0.0 0
2022-10-11 14:30:00-04:00 4.3650 4.370 ... 0.0 0
etc...因此,我可以确认,从pip安装库没有问题,并且在这个时间段内存在数据。如何设置python环境并为其提供库存在一个问题。我建议阅读虚拟环境和pip的文档。
https://stackoverflow.com/questions/74406190
复制相似问题