python - 在 Python 中将 JSON 结构重新排列为数据框
问题描述
我下载的表单中有下面列出的 json 结构。我想把它放在像这种旋转形式的数据框结构中。
日期 账户金额
2019-12-31 资金盈余22165000000
2019-12-31 总计Liab 225307000000
2019-12-31 合计StockholderEquity 33185000000
2019-12-31 少数利益 45000000
2019-12-31 其他CurrentLiab 21454000000
2019-12-31 总资产 258537000000
2019-12-31 普通股票 41000000 。. . 2018-12-31 无形资产 178000000
capitalSurplus 22006000000
totalLiab 220474000000
totalStockholderEquity 35932000000
{'balanceSheetHistory': {'F': [{'2019-12-31': {'capitalSurplus': 22165000000, 'totalLiab': 225307000000, 'totalStockholderEquity': 33185000000, 'minorityInterest': 45000000, 'otherCurrentLiab': 25401000000 ,“ total Assets”:258537000000,'CommonStock':41000000,'其他CurrentAssets':2699000000,'retainingearnings':20320000000,'otherliab':23723000000,'237230000,'threasurystock':-93410000000000000000000000000000000000000000000000000000000岁, 'totalCurrentLiabilities': 98132000000, 'deferredLongTermAssetCharges': 11863000000, 'shortLongTermDebt': 1168000000, 'otherStockholderEquity': -7728000000, 'propertyPlantEquipment': 37869000000, '04700000000, 14'longTermInvestments': 2396000000, 'netTangibleAssets': 33185000000, 'shortTermInvestments': 13851000000, 'netReceivables': 3618000000, 'longTermDebt': 13618000000, 'inventory': 10786000000, 'accountsPayable': 19681000000}}, {'2018-12-31 ':{'intangibleassets':178000000,'CapitalSurplus':22006000000,'totalliab':220474000000,'totalstockholdEreRequity':35932000000,'359320000,'nrumility','nrutilityEts':134000000,'134000000,'deferredlongtermliab'00000 000 000000000000000000000000000000000000000000000来,'commonStock':41000000,'otherCurrentAssets':3930000000,'retainedEarnings':22668000000,'otherLiab':24185000000,'goodWill':264000000,'treasuryStock':-8783000000,'otherAsset: 17245000000, 'cash': 7111000000, 'totalCurrentLiabilities': 95569000000, 'deferredLongTermAssetCharges': 10412000000, 'shortLongTermDebt': 1700000000, 'otherStockholderEquity': -7366000000, 'propertyPlantEquipment': 37883000000, 'totalCurrentAssets': 114649000000, 'longTermInvestments': 2959000000,'NetTangibleassets':35490000000,“短期投资”:15925000000,'NetReceivables':11195000000,'longtermDebt':118333000000,'11833000000,'':11220000000,':11220000000,':21500000,':2152000000000000000000000000000000000000000000000000000000000岁,:2152000; 'intangibleAssets':213000000,'capitalSurplus':21843000000,'totalLiab':222792000000,'totalStockholderEquity':35578000000,'minorityInterest':126000000,'deferredLongTermLiab':232000000,“其他Currentliab”:16402000000,'TotalAssets':258496000000,'CommonStock':41000000,'其他CurrentAssets':3649000000,'retainingainingEarnings':21906000000,'21906000000,'''':25526000000000000000000000000000000000000000000000000000000000000来汇款。 , 'otherAssets': 18091000000, 'cash': 8934000000, 'totalCurrentLiabilities': 94600000000, 'deferredLongTermAssetCharges': 10762000000, 'shortLongTermDebt': 1960000000, 'otherStockholderEquity': -6959000000, 'propertyPlantEquipment': 36901000000, 'totalCurrentAssets': 116801000000, 'longTermInvestments':3448000000,'netTangibleAssets':35290000000,'shortTermInvestments':17554000000,'netReceivables':10599000000,'longTermDebt':13174000000,'inventory': 11176000000, 'accountsPayable': 23282000000}}, {'2016-12-31': {'intangibleAssets': 198000000, 'capitalSurplus': 21630000000, 'totalLiab': 208668000000, 'totalStockholderEquity': 29170000000, 'minorityInterest ':113000000,'其他Currentliab':16277000000,'TotalAssets':237951000000,'CommonStock':41000000,'其他CurrentAssets':3145000000,'retainingaineAreArnings':retainingArearnings':15634000000,'1564000000,'''eatherliab':'''; -8135000000, '其他资产': 14894000000, '现金': 7828000000, 'totalCurrentLiabilities': 90281000000, 'deferredLongTermAssetCharges': 9705000000, 'shortLongTermDebt': 1361000000, '701000000, '7010000000000000000000000000000000000000000000000000000000000000000130030Stockholder 136103000其他持有人的1361030001300propertyPlantEquipment': 33692000000, 'totalCurrentAssets': 108461000000, 'longTermInvestments': 3523000000, 'netTangibleAssets': 28922000000, 'shortTermInvestments': 19642000000, 'netReceivables': 11102000000, 'longTermDebt': 13222000000, 'inventory': 8898000000, 'accountsPayable' : 21296000000}}]}}
解决方案
试试这个代码
cols = ['date','text','valeus']
dat = pd.DataFrame(columns = cols)
dt=#idid copy past the json file
dic=dt['balanceSheetHistory']['F']
for index in range(len(dic)):
for k in list(dic[index].keys()):
for k2 in list(dic[index][k].keys()):
k3=dic[index][k][k2]
#dflist.append([k,k2,dic[index][k][k2]])
dat = dat.append({'date':k, 'text':k2,'valeus':k3},ignore_index=True)
推荐阅读
- amazon-web-services - 如何将已删除的服务恢复到 aws ECS 集群?
- java - 如何从不同的 SQLite 表中获取数据并将其显示在一个 SimpleAdapter Android 中
- c# - 基于泛型 T 的返回列表
- react-router - 从地址栏重新加载 URL 后,Firefox 中的 React Router 导航问题
- angular - 在 observable 中调用返回另一个 observable 的方法时出错
- javascript - 正则表达式/ JavaScript:将字符串拆分为每行最大字符分隔行,并向后查找 n 个字符以查找可能的空格?
- node.js - 将 Azure 自定义视觉模型与 Node.js 结合使用
- ruby-on-rails - 在rails postgresql中转换数据类型时的注意事项
- filenet-p8 - 如何为文件网中的组提供 create_instance 访问权限?
- python-3.x - 我应该如何对不同方向的图像进行分类?