0

I have a JSon object that is written this way.

Data= [{
  "code" : "001",
  "city" : "Boston",
  "zipcode":"067"
  },{
  "code" : "002",
  "city" : "NY",
  },{
  "city" : "NewJersey",
  }]

In order to get a specific value "Code" in an array, I make this way.

ar= Data["code"].Values

When I print results I got

ar = [001, 002 ,'nan']

'nan' seems like the empty value. How can I get only data that exist in the field without taking in consideration these fields where we don't find "code" attribute in ?

1 Answers1

0

What you have shown us is not JSON. It's a list of dicts. If you want to get all the 'code' values out of those dicts, then you could do this:

[d['code'] for d in Data if 'code' in d]
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
  • I still get 'nan' elements in the list when I print it . Let's tackle the problem frpm different corner. Can we delete empty values – user3047512 Nov 29 '13 at 01:35
  • @user3047512 That's a duplicate of [the question you asked just before posting this one](http://stackoverflow.com/q/20276598/198633), which has valid answers on it – inspectorG4dget Nov 29 '13 at 01:36