0

I have a dataframe like below:

House   hexNum              Name   ID1  ID2  DPD    Time1                          Time2                           P1    Pr1 Pr2  Addr    hex2        bool1 bool2 bool3  path
Momma   0x0000000002a71c89  Matt   123  10   0x12   2016-05-18 17:20:57 UTC+0000   2016-05-18 17:20:57 UTC+0000    1555  19  NDN  555.18  0xa1900000  True  True  False  /mnt/c/dir1/thing2
Momma   0x0000000002a71c89  Matt   123  10   0x12   2016-05-18 17:20:57 UTC+0000   2016-05-18 17:20:57 UTC+0000    1555  19  NDN  555.18  0xa2000000  True  False False  /mnt/c/dir1/thing3
Momma   0x0000000002a71c89  Matt   123  10   0x12   2016-05-18 17:20:57 UTC+0000   2016-05-18 17:20:57 UTC+0000    1555  19  NDN  555.18  0xa2100000  False True  False  /mnt/c/dir1/thing4
Dadda   0x0000000002a71c90  Adam   124  10   0x13   2016-05-18 17:20:57 UTC+0000   NaN                             1533  19  NDA  123.23  0xb2800000  True  False False  /mnt/c/dir1/thing2
Dadda   0x0000000002a71c90  Adam   124  10   0x13   2016-05-18 17:20:57 UTC+0000   NaN                             1533  19  NDA  123.23  0xb2900000  True  False True   /mnt/c/dir2/thing3
Dadda   0x0000000002a71c90  Adam   124  10   0x13   2016-05-18 17:20:57 UTC+0000   NaN                             1533  19  NDA  123.23  0xb3000000  True  False False  /mnt/c/dir2/thing4

How can i convert to a nested json output like below? I have tried my hand at the method here "Pandas Dataframe to Nested JSON". This seems like it would do what im looking for but i am having some difficulty with the second nest and additional data. Any help would be appreciated.

[
{"House":"Momma",
    {"Name": "Matt",
        "Name Properties": [{
            "hexNum":"0x0000000002a71c89",
            "ID1":123,
            "ID2":10,
            "DPD":0x12,
            "Time1":"2010-05-18 17:20:57 UTC+0000",
            "Time2":"2016-05-18 17:20:57 UTC+0000",
            "Addr Properties":{
                "Addr":555.18,
                "P1":1555,
                "Pr1":19,
                "Pr2":"NDN"},
            "Path": [
                {"/mnt/c/dir1/thing2":{"hex2":"0xa1900000","bool1":True,"bool2":True,"bool3":False}},
                {"/mnt/c/dir1/thing2":{"hex2":"0xa1900000","bool1":True,"bool2":True,"bool3":False}},
                {"/mnt/c/dir1/thing2":{"hex2":"0xa1900000","bool1":True,"bool2":True,"bool3":False}}
                ]
            }]
    },
},
{"House":"Dadda",   
    {"Name": "Adam",
        "Name Properties": [{
            "hexNum":"0x0000000002a71c89",
            "ID1":123,
            "ID2":10,
            "DPD":0x12,
            "Time1":"2010-05-18 17:20:57 UTC+0000",
            "Time2":"2016-05-18 17:20:57 UTC+0000",
            "Addr Properties":{
                "Addr":555.18,
                "P1":1555,
                "Pr1":19,
                "Pr2":"NDN"},
            "Path": [
                {"/mnt/c/dir1/thing2":{"hex2":"0xa1900000","bool1":True,"bool2":True,"bool3":False}},
                {"/mnt/c/dir1/thing2":{"hex2":"0xa1900000","bool1":True,"bool2":True,"bool3":False}},
                {"/mnt/c/dir1/thing2":{"hex2":"0xa1900000","bool1":True,"bool2":True,"bool3":False}}
                ]
            }]
    }
}
]
johnnyb
  • 1,745
  • 3
  • 17
  • 47

0 Answers0