I'm messing around with pandas to process rather nasty json. I can't quite figure out how to create dataframe from only selected elements. I understand this has to be flattened first but while i'm succesful at that I can't figure out how to combine elements that are "higher" in the json structure with those that are lower eg. deeper in it.
I'm linking part of json im working on for reference. How would I create an output that consists only of each vault name from autofarm-> lpvaults->vaults->name and currenttoken0 currenttoken1 from lpinfo 1 step deeper? I managed to flatted it so dataframe consists of all key, value for some other dict but i can't quite comprehend how to filter it out and mix records from different layers of complexity together.
[ { "status":"1", "message":"OK", "result":{ "watchBalance":{}, "currencies":{}, "Alpha":{}, "HyperJump":{}, "BeefyFinance":{}, "Blizzard":{}, "MDex":{}, "PancakeSwap":{}, "Jetfuel":{}, "bDollar":{}, "Autofarm":{ "vaults":{}, "LPVaults":{ "totalUSDValues":{ "deposit":24485.47243224253, "yield":962.457450784509, "total":25447.92988302704 }, "vaults":[ { "name":"AUTO-WBNB Pool", "id":6, "type":"lpVault", "contractAddress":"0x4d0228EBEB39f6d2f29bA528e2d15Fc9121Ead56", "platform":"auto", "depositToken":"AUTO-WBNB LP", "depositTokenAddress":"0x4d0228EBEB39f6d2f29bA528e2d15Fc9121Ead56", "rewardToken":"AUTO", "priceInUSDRewardToken":3314.101698507455, "currentTokens":0.5294501275850915, "apy":2.0380000000000003, "pendingRewards":1.847392858328e-06, "harvestedRewards":0.017871390179342642, "totalRewards":null, "depositedTokens":0.5294501275850915, "priceInUSDDepositToken":2981.0755976900623, "vaultSessions":[ ], "LPInfo":{ "compactSessions":[
], "symbolToken0":"AUTO", "symbolToken1":"WBNB", "depositToken0":0.25949385449535795, "depositToken1":1.1955198025887595, "priceInUSDToken0":3314.101698507455, "priceInUSDToken1":621.4508782985882, "changeToken0":-0.021710153126664244, "changeToken1":0.07282194285579924, "feesEarnedInToken0":0.0006273698267266132, "feesEarnedInToken1":0.0033463998435951936, "winningsToken0":0, "winningsToken1":0, "currentToken0":0.238097386282057, "currentToken1":1.2700149453663563, "poolToken0":10925.480395918756, "poolToken1":58276.67243556639, "actPrice":5.334014645006897, "hodlInToken1":2.579663822756287, "actInToken1":2.5400298907327126, "ILInToken1":-0.042980331867169645, "faktorIL":-0.016661214336543495, "depositPrice":1 } }, {}, {}, {} ] } }, key:{value} }
} ]
https://stackoverflow.com/questions/67378279/nested-json-parsing-using-pandas May 04, 2021 at 11:05AM
没有评论:
发表评论