Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError 'currencyCode' in get_financial_data() #271

Open
Scoodood opened this issue Mar 26, 2024 · 3 comments
Open

KeyError 'currencyCode' in get_financial_data() #271

Scoodood opened this issue Mar 26, 2024 · 3 comments

Comments

@Scoodood
Copy link

Describe the bug
get_financial_data() is crashing

To Reproduce
Steps to reproduce the behavior:

import yahooquery as yq

aapl = yq.Ticker('aapl')
aapl.get_financial_data(
    frequency='a',
    types=['PeRatio', 'PegRatio', 'PsRatio', 'PbRatio']
)

Expected behavior
I expect the function to return a pandas Dataframe with those values

Screenshots

File c:\Users\xxx\miniconda3\envs\py311\Lib\site-packages\pandas\core\groupby\grouper.py:1043, in get_grouper(obj, key, axis, level, sort, observed, validate, dropna)
   1041         in_axis, level, gpr = False, gpr, None
   1042     else:
-> 1043         raise KeyError(gpr)
   1044 elif isinstance(gpr, Grouper) and gpr.key is not None:
   1045     # Add key to exclusions
   1046     exclusions.add(gpr.key)

KeyError: 'currencyCode'

Desktop (please complete the following information):

  • Win11 Pro
  • Python 3.12
@ms82494
Copy link

ms82494 commented Mar 27, 2024

I think the problem is that the valuation ratios you're trying to retrieve, 'PeRatio', 'PegRatio', and 'PbRatio', aren't found in financial statements. Take a look at the documentation for the get_financial_data function here. Valid elements for the types list are (mostly) listed in the documentation.

@Scoodood
Copy link
Author

But the keys that I used to retrieve those ratios were listed in the documentation. From your link, just scroll down a bit more and you will see this.

image

@ms82494
Copy link

ms82494 commented Mar 29, 2024

My apologies, you are correct! And trying your code, I get the same error as you do.

I had never tried to retrieve these valuation measures from the financial statements because logically, they don't seem to belong there. They are market-based metrics that continually change as the stock price moves, and they aren't reported by companies in their quarterly filings. Maybe at one point Yahoo Finance had these stats in the "Financials" tab of their stock pages, but they are now found on the "Statistics" tab.

You can now get the data you need from the valuation_measures attribute of the Ticker object, see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants