簡體   English   中英

如何從雅虎金融(Python)重新排序數據?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM