Reading output from yahoofinancials

2369 views python
-1

How to read the output from yahoofinancials 1.5 ref. [https://pypi.org/project/yahoofinancials/]
I'm new to Python, and need help to address the returned JSON Data output from:

from yahoofinancials import YahooFinancials  
yahoo_financials = YahooFinancials('AAPL')  
print(yahoo_financials.get_financial_stmts('annual', 'income'))**

first few lines of non ordered output:

{'incomeStatementHistory': {'AAPL': [{'2019-09-28': {'researchDevelopment': 16217000000, 'effectOfAccountingCharges': None, 'incomeBeforeTax': 65737000000, 'minorityInterest': None, 'netIncome': 55256000000, 'sellingGeneralAdministrative': 18245000000, 'grossProfit': 98392000000, 'ebit': 63930000000, 'operatingIncome': 63930000000, 'otherOperatingExpenses': None, 'incomeBeforeTax': 65737000000, 'minorityInterest': None, 'netIncome': 55256000000, . . . . .}

My output is with single quotes and not double quotes as expected, but contain all 4 year, OK.

I can address a single year by:

income['incomeStatementHistory']['DSV.CO'][0]  

get ordered output key value in each line:

{'2018-12-31': {'researchDevelopment': None'effectOfAccountingCharges': None,
'incomeBeforeTax': 5201000000,
'minorityInterest': -29000000,
'netIncome': 4000000000,
'sellingGeneralAdministrative': 11301000000,
'grossProfit': 17489000000,
'ebit': 5426000000,
'operatingIncome': 5426000000,
'otherOperatingExpenses': None,
'interestExpense': -355000000,
'extraordinaryItems': None,
'nonRecurring': None,
'otherItems': None,
'incomeTaxExpense': 1213000000,
'totalRevenue': 79053000000,
'totalOperatingExpenses': 73627000000,
'costOfRevenue': 61564000000,
'totalOtherIncomeExpenseNet': -225000000,
'discontinuedOperations': None,
'netIncomeFromContinuingOps': 3988000000,
'netIncomeApplicableToCommonShares': 4000000000}}

Here I want to adress a few single data items, but nothing works for me. Please help.

When I try to address 'ebit':

    income['incomeStatementHistory']['DSV.CO'][0]['ebit']

I get the following error:


KeyError         Traceback (most recent call last)
ipython-input-12-66fa46d51257> in module>

-----> 1 incom['incomeStatementHistory']['DSV.CO'][0]['ebit']

KeyError: 'ebit'

I also want to get EBITDA, where do I get it? It is included from Yahoo.

I can get a few single data-items by: get_total_revenue() and get_net_income(), but only from the last year. Can it be made to take year and or quorter as a parameter.

I'm using Windows 10 and Python 3.7

Any help will be much appreciated.

answered question

1 Answer

6

Per your code, there is one more layer of date element to reach ebit:

income['incomeStatementHistory']['DSV.CO'][0]['2018-12-31']['ebit']

posted this

Have an answer?

JD

Please login first before posting an answer.