作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何读取 yahoofinancials 1.5 引用的输出。 [ https://pypi.org/project/yahoofinancials/]
我是 Python 新手,需要帮助来解决从以下位置返回的 JSON 数据输出:
from yahoofinancials import YahooFinancials
yahoo_financials = YahooFinancials('AAPL')
print(yahoo_financials.get_financial_stmts('annual', 'income'))**
{'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, . . . . .}
data = yahoofinancials.getfinancial_stmts('annual', 'income')
data['incomeStatementHistory']['DSV.CO'][0]
{'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}}
data['incomeStatementHistory']['DSV.CO'][0]['ebit']
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
ipython-input-12-66fa46d51257> in module>
-----> 1 data['incomeStatementHistory']['DSV.CO'][0]['ebit']
KeyError: 'ebit'
最佳答案
当您在@PaulLo 中删除答案时-您无法直接获得 ebit
因为有像这样的日期
data['incomeStatementHistory']['AAPL'][0]['2019-09-28']['ebit']
data['incomeStatementHistory']['AAPL'][1]['2019-09-29']['ebit']
data['incomeStatementHistory']['AAPL'][2]['2019-09-30']['ebit']
.keys()
看到不同的日期。
print( data['incomeStatementHistory']['AAPL'][0].keys() ) # ['2019-09-28']
print( data['incomeStatementHistory']['AAPL'][1].keys() ) # ['2019-09-29']
print( data['incomeStatementHistory']['AAPL'][2].keys() ) # ['2019-09-30']
.keys()
的日期。或使用
.items()
或
.values()
from yahoofinancials import YahooFinancials
yahoo_financials = YahooFinancials('AAPL')
data = yahoo_financials.get_financial_stmts('annual', 'income')
#print( data['incomeStatementHistory']['AAPL'][0].keys() ) # ['2019-09-28']
#print( data['incomeStatementHistory']['AAPL'][1].keys() ) # ['2019-09-29']
#print( data['incomeStatementHistory']['AAPL'][2].keys() ) # ['2019-09-30']
for item in data['incomeStatementHistory']['AAPL']:
for key, val in item.items():
print(key, val['ebit'])
2019-09-28 63930000000
2018-09-29 70898000000
2017-09-30 61344000000
2016-09-24 60024000000
关于python - 读取 yahoofinancials 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59278589/
如何读取 yahoofinancials 1.5 引用的输出。 [ https://pypi.org/project/yahoofinancials/] 我是 Python 新手,需要帮助来解决从以下
我有以下代码 from mysql.connector import MySQLConnection, Error from yahoofinancials import YahooFinancial
我是一名优秀的程序员,十分优秀!