[英]How to reorder Data from yahoo finance(Python)?
我正在尝试写下一个 python 脚本,该脚本允许我从 Yahoo.I 获取一些财务报表项目。我尝试使用 yahoofinancials 库,但我只能获得一整页数据:例如,使用以下代码:
from yahoofinancials import YahooFinancials
yahoo_financials = YahooFinancials('AAPL')
print(yahoo_financials.get_financial_stmts('annual', 'balance'))
我会得到这个:
{
"balanceSheetHistory": {
"AAPL": [
{
"2016-09-24": {
"otherCurrentLiab": 8080000000,
"otherCurrentAssets": 8283000000,
"goodWill": 5414000000,
"shortTermInvestments": 46671000000,
"longTermInvestments": 170430000000,
"cash": 20484000000,
"netTangibleAssets": 119629000000,
"totalAssets": 321686000000,
"otherLiab": 36074000000,
"totalStockholderEquity": 128249000000,
"inventory": 2132000000,
"retainedEarnings": 96364000000,
"intangibleAssets": 3206000000,
"totalCurrentAssets": 106869000000,
"otherStockholderEquity": 634000000,
"shortLongTermDebt": 11605000000,
"propertyPlantEquipment": 27010000000,
"deferredLongTermLiab": 2930000000,
"netReceivables": 29299000000,
"otherAssets": 8757000000,
"longTermDebt": 75427000000,
"totalLiab": 193437000000,
"commonStock": 31251000000,
"accountsPayable": 59321000000,
"totalCurrentLiabilities": 79006000000
}
}
]
}
}
我想获取每个元素,例如“现金”,并将其放入包含所有这些数据的变量或数组中,以便获取单个数字。 因此,例如,如果我要获得“现金”,我将有一个变量或数组/列表允许我获得数字(在本例中为 20484000000,用于现金)。 我希望我已经说清楚了。 有人知道怎么做吗?谢谢。
由于 output 是 json 格式,我们必须使用 json。
from yahoofinancials import YahooFinancials
import json
yahoo_financials = YahooFinancials('AAPL')
w = yahoo_financials.get_financial_stmts('annual', 'balance')
print(w["balanceSheetHistory"]["AAPL"][2]['2019-09-28']['totalLiab'])
更改“totalLiab”以获得所需的数据,要更改“2019-09-28”,您还必须更改 [2]。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.