KeyError: "['Dividends'] not in index" #192
Replies: 4 comments
-
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the fast reply, @JerBouma . Much appreciated! Very strange. When I use exactly new code (btw also thanks for pointing me I should use a code snipper, I'll adapt), I get a different result: from financetoolkit import Toolkit
import financedatabase as fd
equities = fd.Equities()
belist = equities.select(country='Belgium', only_primary_listing=True)
belist_list = list(belist.index)
instance = Toolkit(belist_list, api_key=API_KEY, enforce_source="FinancialModelingPrep")
instance.get_historical_data()
I have an FMP Starter Plan: that should not play a role? I have not bottleneck in bandwith or api calls. Don't know if this helps: When I remove enforce_source="FinancialModelingPrep" from financetoolkit import Toolkit
import financedatabase as fd
equities = fd.Equities()
belist = equities.select(country='Belgium', only_primary_listing=True)
belist_list = list(belist.index)
instance = Toolkit(belist_list, api_key=API_KEY)
instance.get_historical_data()
Python version: 3.13.7 |
Beta Was this translation helpful? Give feedback.
-
|
Hi, sorry for the late response. The issue here is simply that a specific ticker doesn't have any dividends. In the code I run the following line: historical_data = historical_data[
["Open", "High", "Low", "Close", "Adj Close", "Volume", "Dividends"]
]That won't work if "Dividends" is not available. A simple fix therefore is: if "Dividends" not in historical_data:
# If there are no dividends, create a column with 0.0 values
historical_data["Dividends"] = 0.0I'll add this in the next release, I'll inform you once this release is available. |
Beta Was this translation helpful? Give feedback.
-
|
Please see v2.0.6 in which this issues is fixed. |
Beta Was this translation helpful? Give feedback.




Uh oh!
There was an error while loading. Please reload this page.
-
Does this look familiar?
import financedatabase as fd
from financetoolkit import Toolkit
import os
API_KEY = os.getenv("FMP_API_KEY")
if not API_KEY:
raise RuntimeError("FMP_API_KEY is not set in the environment.")
equities = fd.Equities()
belist = equities.select(
country='Belgium',
only_primary_listing=True
)
toolkit = belist.to_toolkit(
api_key=API_KEY
)
toolkit.get_historical_data()
Obtaining historical data: 78%|███████▊ | 38/49 [00:04<00:01, 9.31it/s]$NYXFF: possibly delisted; no timezone found
Exception in thread Thread-90 (worker):
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 1043, in _bootstrap_inner
self.run()
~~~~~~~~^^
File "/Applications/workspace/.venv/lib/python3.13/site-packages/ipykernel/ipkernel.py", line 772, in run_closure
_threading_Thread_run(self)
~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 994, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Applications/workspace/.venv/lib/python3.13/site-packages/financetoolkit/historical_model.py", line 175, in worker
historical_data = yfinance_model.get_historical_data(
ticker=ticker,
...<6 lines>...
fallback=attempted_fmp,
)
File "/Applications/workspace/.venv/lib/python3.13/site-packages/financetoolkit/yfinance_model.py", line 229, in get_historical_data
historical_data = historical_data[
~~~~~~~~~~~~~~~^
["Open", "High", "Low", "Close", "Adj Close", "Volume", "Dividends"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
]
^
...
File "/Applications/workspace/.venv/lib/python3.13/site-packages/pandas/core/indexes/base.py", line 6264, in _raise_if_missing
raise KeyError(f"{not_found} not in index")
KeyError: "['Dividends'] not in index"
Obtaining historical data: 100%|██████████| 49/49 [00:05<00:00, 9.39it/s]
historical data are loaded until 2025-09-08
not for 2025-09-09 2025-09-10 2025-09-11 2025-09-12
Beta Was this translation helpful? Give feedback.
All reactions