因此,我与一家小型项目(im)的 block子公司合作。 目前,Im试图将json数据输入Pandas数据机,然后将这一数据仪转换成一个由第三方项目“CurseXcel”处理、但I digress。
目前遇到麻烦的是,在json数据字典清单中正确处理儿童。 能够制定哪些法典,基本上就是
def return_pandas():
process = subprocess.run("lsblk --json -o NAME,SIZE,UUID,MOUNTPOINT,PATH,FSTYPE ".split(), capture_output=True, text=True)
data = json.loads(process.stdout)
return pd.json_normalize(data[ blockdevices ])
当时
json_pandas = return_pandas()
返回
name size uuid mountpoint path fstype children
0 sda 25G None None /dev/sda None NaN
1 sdb 25G None None /dev/sdb None [{ name : sdb1 , size : 512M , uuid : 008...
2 sr0 1024M None None /dev/sr0 None NaN
as a table. Again, what i m having trouble with is getting the children list within said json and pandas dataframe table to be potentially listed alongside regular devices or listed in a more normalized fashion within the children column comprising name size uuid etc. This would involve potentially using recursion to flatten all data or something else.
假设数据就是如此。
[[ sda 25G None None /dev/sda None nan]
[ sdb 25G None None /dev/sdb None
list([{ name : sdb1 , size : 512M , uuid : 0087-DF28 , mountpoint : /boot/efi , path : /dev/sdb1 , fstype : vfat }, { name : sdb2 , size : 488M , uuid : bd51147c-8f8c-4d3a-afde-4ebf67ae4558 , mountpoint : /boot , path : /dev/sdb2 , fstype : ext2 }, { name : sdb3 , size : 24G , uuid : d07d17bf-ebbd-491a-b57c-f9d43b7e6be5 , mountpoint : None, path : /dev/sdb3 , fstype : crypto_LUKS , children : [{ name : sda3_crypt , size : 24G , uuid : 3NbbDi-BtQ4-PXzK-NVBO-cR2d-aLzZ-pzh0A5 , mountpoint : None, path : /dev/mapper/sda3_crypt , fstype : LVM2_member , children : [{ name : kali--vg-root , size : 23G , uuid : 6bc26692-9b22-4d38-b1c0-53e99326e9d5 , mountpoint : / , path : /dev/mapper/kali--vg-root , fstype : ext4 }, { name : kali--vg-swap_1 , size : 980M , uuid : 3eb8e4cc-56bb-4b5b-b2a8-bc7ac016df67 , mountpoint : [SWAP] , path : /dev/mapper/kali--vg-swap_1 , fstype : swap }]}]}])]
[ sr0 1024M None None /dev/sr0 None nan]]
如果在把桌子变成一个绝食阵列之后,我就能够拿到这份名单,因为这样一来就 great了不起的一些how。 损失一米,但可以肯定的是,损失只是一米。
this could involve flattening into a 1 dimensional array however i still want to maintain the ability to use numpyarrays. i ve thought about using recursion however dont know specifically how to grab a nested list without recreating the entire structure, nor a conditional statement that applies to nested list.
每项要求的数据
{ blockdevices : [{ name : sda , size : 25G , uuid : None, mountpoint : None, path : /dev/sda , fstype : None}, { name : sdb , size : 25G , uuid : None, mountpoint : None, path : /dev/sdb , fstype : None, children : [{ name : sdb1 , size : 512M , uuid : 0087-DF28 , mountpoint : /boot/efi , path : /dev/sdb1 , fstype : vfat }, { name : sdb2 , size : 488M , uuid : bd51147c-8f8c-4d3a-afde-4ebf67ae4558 , mountpoint : /boot , path : /dev/sdb2 , fstype : ext2 }, { name : sdb3 , size : 24G , uuid : d07d17bf-ebbd-491a-b57c-f9d43b7e6be5 , mountpoint : None, path : /dev/sdb3 , fstype : crypto_LUKS , children : [{ name : sda3_crypt , size : 24G , uuid : 3NbbDi-BtQ4-PXzK-NVBO-cR2d-aLzZ-pzh0A5 , mountpoint : None, path : /dev/mapper/sda3_crypt , fstype : LVM2_member , children : [{ name : kali--vg-root , size : 23G , uuid : 6bc26692-9b22-4d38-b1c0-53e99326e9d5 , mountpoint : / , path : /dev/mapper/kali--vg-root , fstype : ext4 }, { name : kali--vg-swap_1 , size : 980M , uuid : 3eb8e4cc-56bb-4b5b-b2a8-bc7ac016df67 , mountpoint : [SWAP] , path : /dev/mapper/kali--vg-swap_1 , fstype : swap }]}]}]}, { name : sr0 , size : 1024M , uuid : None, mountpoint : None, path : /dev/sr0 , fstype : None}]}