Reputation: 1
Yahoo_fin was working fine a couple days ago and my entire project was working fine but today when I ran the same code it did not work.I have imported all functions using "from yahoo_fin.stock_info import *". When I checked to see whether all the functions were working on thier own, some of the functions were working but others were not. I am getting this error whenever I call
get_day_gainers()
File "C:\Users\serve\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3652, in get_loc
return self._engine.get_loc(casted_key)
File "pandas_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: '52 Week Range'
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "c:\Users\serve\OneDrive\stocktrader\main.py", line 7, in stocksDataFrame = get_day_gainers() File "C:\Users\serve\AppData\Local\Programs\Python\Python310\lib\site-packages\yahoo_fin\stock_info.py", line 620, in get_day_gainers return _raw_get_daily_info(f"https://finance.yahoo.com/gainers?offset=0&count={count}") File "C:\Users\serve\AppData\Local\Programs\Python\Python310\lib\site-packages\yahoo_fin\stock_info.py", line 595, in _raw_get_daily_info del df["52 Week Range"] File "C:\Users\serve\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py", line 4279, in delitem loc = self.axes[-1].get_loc(key) File "C:\Users\serve\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3654, in get_loc raise KeyError(key) from err KeyError: '52 Week Range'
Some functions were working fine and others weren't
For example the get_live_price() function worked fine for me:
currentPrice = get_live_price("AAPL") print(currentPrice)
returned the correct info.but other functions I need like get_day_gainers() didn't work:
minGrowthPercentage = 10
for i in range(0,len(get_day_gainers()["% Change"])):
if (float(get_day_gainers()["% Change"][i]) < minGrowthPercentage):
return foundStocks
or even extremely basic calls like
stocksDataFrame = get_day_gainers()
print(stocksDataFrame)
I have tried to update the API and tried a lot of the functions within the API and about half worked and the other half didn't. Previously all functions worked fine. I am thinking this is an issue with the way the API is scraping the data and loading it into a Dataframe but I might be completely wrong. Any help or advice would be greatly appreciated.
Upvotes: 0
Views: 107