简体   繁体   中英

Extract title of nested json using pandas

{
  "Ankle" : {
    "1544095214100" : {
      "AX" : -0.3310394287109375,
      "AY" : -0.3018035888671875,
      "AZ" : 9.595489501953125
    },
    "1544095214200" : {
      "AX" : -0.3290557861328125,
      "AY" : -0.2254791259765625,
      "AZ" : 9.609939575195312
    },
    "1544095214500" : {
      "AX" : -0.32763671875,
      "AY" : -0.22491455078125,
      "AZ" : 9.612503051757812
    }
  } ,
  "Head" : {
    "1544095207100" : {
      "AX" : -0.32867431640625,
      "AY" : -0.2235870361328125,
      "AZ" : 9.608489990234375
    },

Currently my JSON file looks like this. I am using pandas and I would like to extract all the timestamp values (ie: 1544095214100) from "Ankles" and add them to an array. How could I achieve this?

DeepSpace is correct. Dont get too caught up using libraries like pandas, for this just use Python.

d = {
  "Ankle" : {
    "1544095214100" : {
      "AX" : -0.3310394287109375,
      "AY" : -0.3018035888671875,
      "AZ" : 9.595489501953125
    },
    "1544095214200" : {
      "AX" : -0.3290557861328125,
      "AY" : -0.2254791259765625,
      "AZ" : 9.609939575195312
    },
    "1544095214500" : {
      "AX" : -0.32763671875,
      "AY" : -0.22491455078125,
      "AZ" : 9.612503051757812
    }
  } ,
  "Head" : {
    "1544095207100" : {
      "AX" : -0.32867431640625,
      "AY" : -0.2235870361328125,
      "AZ" : 9.608489990234375
    }
  }
}

myList = []
for key in d['Ankle'].keys():
    myList.append(key)

print(myList)

So, in the example above, just substitute you array for myList.

If you want to do more with Anker and find out Math.sqrt , do following:

myList = []
for key,value in d['Ankle'].iteritems():
    temp=[key,value]
    myList.append(temp)

Now you can traverse myList to the 2nd set of ooperations

Try myList[0] myList[0][1] and myList[0][1]["AX"] commands to get the next steps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM