I am trying to make a program that emails alerts when a stock price crosses a moving average and I am using the library yahoo_fin
(Here are the docs)
I am trying to get the moving average data from yahoo_fin.stock_info.get_stats('a')
but I am getting the following error:
File "lib\site-packages\yahoo_fin\stock_info.py", line 241, in get_stats
table.columns = ["Attribute" , "Value"]
File "lib\site-packages\pandas\core\generic.py", line 5287, in __setattr__
return object.__setattr__(self, name, value)
File "pandas\_libs\properties.pyx", line 67, in pandas._libs.properties.AxisProperty.__set__
File "lib\site-packages\pandas\core\generic.py", line 661, in _set_axis
self._data.set_axis(axis, labels)
File "lib\site-packages\pandas\core\internals\managers.py", line 178, in set_axis
f"Length mismatch: Expected axis has {old_len} elements, new "
ValueError: Length mismatch: Expected axis has 9 elements, new values have 2 elements
Any help on fixing this would be great!
If you don't know how to get this particular function to work, another alternative I tried and which seems to work is to use the method yahoo_fin.stock_info.get_data('a')
, but I would need help to know how to calculate the moving average from this data.
yahoo_fin
are you using? it works onpython 3.6
andyahoo_fin 0.8.4
. Also, could you give a bit more code context? what modules are you importing? – user7440787python -c "import yahoo_fin; from yahoo_fin import stock_info; print(yahoo_fin.stock_info.get_data('a'))"
. Try a different version of pandas? which version of pandas are you using? – user7440787get_stats
also workspython -c "import yahoo_fin; from yahoo_fin import stock_info; print(yahoo_fin.stock_info.get_stats('a'))"
and I am using the same version ofpandas
. Sorry – user7440787