如何将大的嵌套集合分割成独立的集合?



嗨,我有一组数据,我从api中提取,我正试图将数据分成单独的集合,因为目前它们都嵌套在较大的集合中。

我的当前集:

api = {
"9/30/2018": {
"Capital Expenditure": "-13313000", 
"End Cash Position": "25913000", 
"Financing Cash Flow": "-87876000", 
"Free Cash Flow": "64121000", 
"Income Tax Paid Supplemental Data": "10417000", 
"Interest Paid Supplemental Data": "3022000", 
"Investing Cash Flow": "16066000", 
"Issuance of Capital Stock": "669000", 
"Issuance of Debt": "6969000", 
"Operating Cash Flow": "77434000", 
"Repayment of Debt": "-6500000", 
"Repurchase of Capital Stock": "-72738000"
}, 
"9/30/2019": {
"Capital Expenditure": "-10495000", 
"End Cash Position": "50224000", 
"Financing Cash Flow": "-90976000", 
"Free Cash Flow": "58896000", 
"Income Tax Paid Supplemental Data": "15263000", 
"Interest Paid Supplemental Data": "3423000", 
"Investing Cash Flow": "45896000", 
"Issuance of Capital Stock": "781000", 
"Issuance of Debt": "6963000", 
"Operating Cash Flow": "69391000", 
"Repayment of Debt": "-8805000", 
"Repurchase of Capital Stock": "-66897000"
}, 
"9/30/2020": {
"Capital Expenditure": "-7309000", 
"End Cash Position": "39789000", 
"Financing Cash Flow": "-86820000", 
"Free Cash Flow": "73365000", 
"Income Tax Paid Supplemental Data": "9501000", 
"Interest Paid Supplemental Data": "3002000", 
"Investing Cash Flow": "-4289000", 
"Issuance of Capital Stock": "880000", 
"Issuance of Debt": "16091000", 
"Operating Cash Flow": "80674000", 
"Repayment of Debt": "-12629000", 
"Repurchase of Capital Stock": "-72358000"
}, 
"ttm": {
"Capital Expenditure": "-9646000", 
"End Cash Position": "35276000", 
"Financing Cash Flow": "-94328000", 
"Free Cash Flow": "94768000", 
"Income Tax Paid Supplemental Data": "19627000", 
"Interest Paid Supplemental Data": "2597000", 
"Investing Cash Flow": "-9849000", 
"Issuance of Capital Stock": "1011000", 
"Issuance of Debt": "22370000", 
"Operating Cash Flow": "104414000", 
"Repayment of Debt": "-7500000", 
"Repurchase of Capital Stock": "-83410000"
}
}

我期望的结果是:s_19_30_2018 = ["资本支出"-13313000"…]

s_19_30_2019 = ["资本支出"; "-10495000"…]

s_19_30_2020 =["资本Expenditure"-7309000"…]

s_ttm =["资本Expenditure"-9646000"…]

这样我就可以更容易地访问数据并将它们添加到sql数据库中。

我已经尝试过做s_19_30_2018 = api['19/30/2018'],但我一直得到'类型错误字符串索引必须是整数'。

python>.<</p>

给定这个结构:

api = {
"9/30/2018": {
"Capital Expenditure": "-13313000", 
"End Cash Position": "25913000", 
}, 
"9/30/2019": {
....

获取键的列表,第一个条目的值可以运行:

for key,value in api["9/30/2018"]:
l = [key, value]
print(f" {key}, {value}")
# prints "Capital Expenditure -133313000"

浏览所有项目

#get the keys
ks = api.keys()
for k in ks:
for key, value, in api[k]:
print(f" {key}, {value}")
# prints "Capital Expenditure -133313000"] ...

您的字典键是字符串,所以当您访问它们时使用引号,如

s_19_30_2018 = api["9/30/2018"]

我也没有看到任何关键字,如"19_30_2018"在你的字典里。

ks = api.keys()
for k in ks:
for key, value, in api[k]:
print(f" {key}, {value}")

通过使用代码你可以解决你的问题。

使用以下代码.....你可以解决你的问题

ks = api.keys()
for k in ks:
for key, value, in api[k]:
print(f" {key}, {value}")

相关内容

  • 没有找到相关文章

最新更新