我在数据框'tt'下方有第二列'underlier'是字典键的列表,其中两个键是underliersecurityid和fxspot
我想创建一个数据框作为输出,该数据框从下层目录中取出密钥并放入每个企业ID中。例如:
EnterpriseID,underliersecurityid,fxspot
我可以规范下层列本身,但是我一直在丢失企业ID。请建议是否有某种方法可以解决这个问题
tt = bn.iloc[:,[4,-7]]
tt
ttu = pd.DataFrame(bn.iloc[:,-7].values.tolist()).dropna()
ttu
ttu2 = pd.DataFrame(ttu.iloc[:,0].values.tolist()).dropna()
ttu2
综合数据。explode()
该列表然后使用json_normalize()
上的输出to_dict()
扩展字典入列
tt = pd.DataFrame([{"enterpriseid":"abcd","underlyer":[{"underlyersecurityid":"SWAP10Y","fmspot":[]}]}])
pd.json_normalize(tt.explode("underlyer").to_dict(orient="records"))
enterpriseid underlyer.underlyersecurityid underlyer.fmspot
abcd SWAP10Y []
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句