3

我一直在尝试从雅虎财经中提取数据,但我不断收到这个奇怪的错误。

所以我运行这段代码:

#Importing Modules/Libraries
import pandas as pd

pd.core.common.is_list_like = pd.api.types.is_list_like

from pandas_datareader import data, wb

import fix_yahoo_finance as yf

yf.pdr_override()

import numpy as np

import datetime

import seaborn as sns

import matplotlib.pyplot as plt



And I get a feedback from my console with this error :
#Importing Modules/Libraries

import pandas as pd

pd.core.common.is_list_like = pd.api.types.is_list_like

from pandas_datareader import data, wb

import fix_yahoo_finance as yf

yf.pdr_override()

import numpy as np

import datetime

import seaborn as sns

import matplotlib.pyplot as plt

#Importing Historical data from yahoo finance

tickers = 

['XSLV','SMLV','XMLV','USMV','LGLV','SPLV','PRFZ','PXSC','FNDB','PXMC','PRF','QQ

EW','RSP','EQWL','EQAL','EWMC','EWSC',


'DWAS','MMTM','PDP','DWAQ','QUAL','SPHQ','^PHB','ACWV','IDLV','EELV','PDN','PXH'

,'QWLD','IQLT','IQDF','IDMO','EEMO',

  'PIZ','PIE']

indices = pd.DataFrame()

for t in tickers:indices[t]=data.get_data_yahoo(t, data_source='yahoo',start='2016-1-1')['Adj Close']

输出:

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

[                       0%                       ]

[*********************100%***********************]  1 of 1 downloaded

Traceback (most recent call last):

 File "<input>", line 18, in <module>

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\fix_yahoo_finance\__init__.py", line 202, in download

'Close', 'Adj Close', 'Volume']]

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\frame.py", line 2682, in __getitem__

return self._getitem_array(key)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\frame.py", line 2726, in _getitem_array

indexer = self.loc._convert_to_indexer(key, axis=1)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexing.py", line 1308, in _convert_to_indexer

obj, kind=self.name)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexes\multi.py", line 1968, in _convert_listlike_indexer

_, indexer = self.reindex(keyarr, level=level)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexes\multi.py", line 2057, in reindex

keep_order=False)

 File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\pandas\core\indexes\base.py", line 3969, in _join_level

ngroups = 1 + new_lev_labels.max()

File "C:\Users\TIM\PycharmProjects\BILLIONAIRE'S CLUB\venv\lib\site-

packages\numpy\core\_methods.py", line 26, in _amax

return umr_maximum(a, axis, None, out, keepdims)

ValueError: zero-size array to reduction operation maximum which has no identity.
4

2 回答 2

0

您需要指定 end_date。日期也必须采用“YYYY-MM-DD”格式。

import fix_yahoo_finance as yahoo

spx_df = yahoo.download("^GSPC", "2015-01-01", "2019-04-28')
spx_df.Close.plot()

在此处输入图像描述

于 2019-04-28T13:08:26.337 回答
0

这是在 Yahoo 上设置的速率限制。您可以尝试并通过以避免值错误。

像这样的东西:

for ticker in tickers1:
    try:
        df = yahoo.download(self.TICK_SYMBOLS, start = self.START, end = datetime.now())
        df.reset_index(inplace = True)
        df.set_index("Date", inplace = True)

    except ValueError:
        pass
于 2018-12-06T02:01:35.753 回答