Parsing Json in Python Null data -


suppose have following 2 json.

a={"id": "tuxnqkfhvunbtta0",   "name": "campestre 1a. secc.",   "city": {     "id": "tuxnq0fhvtk2njy",     "name": "aguascalientes"   },   "state": {     "id": "tuxnuefhvtmwnje",     "name": "aguascalientes"   },   "country": {     "id": "mx",     "name": "mexico"   },   "geo_information": none,   "subneighborhoods": [   ] }  b={   "id": "tuxntuxnqkfhvtnosg",   "name": "aeropuerto aguascalientes (lic. jesus teran peredo)",   "city": {     "id": "tuxnq0fhvtk2njy",     "name": "aguascalientes"   },   "state": {     "id": "tuxnuefhvtmwnje",     "name": "aguascalientes"   },   "country": {     "id": "mx",     "name": "mexico"   },   "geo_information": {     "location": {       "latitude": 21.701155,       "longitude": -102.31439     }   },   "subneighborhoods": [   ] }   print b 

and want create table 'locations' next columns:

locations = pandas.dataframe(columns=['city_id', 'city_name', 'name', 'latitud', 'longitud', 'country_id', 'country_name', 'state_id', 'state_name', 'subneighborhoods', 'id'])

expect have following data:

i expect have following table

tuxnqkfhvunbtta0, campestre 1a. secc., tuxnq0fhvtk2njy, aguascalientes, tuxnuefhvtmwnje, aguascalientes, mx, mexico, null, null, [] tuxntuxnqkfhvtnosg, aeropuerto aguascalientes (lic. jesus teran peredo), tuxnq0fhvtk2njy, aguascalientes, tuxnuefhvtmwnje, aguascalientes, mx, mexico, 21.701155,  -102.31439, [] 

as in 'a' geo_information none, can not create table. how con solve issue?

thanks!

did try json_normalizer? request, dot instead of underline.

in[1]: pandas.io.json import json_normalize  in[2]: pd.dataframe(json_normalize([a,b])) out[2]:             city.id       city.name country.id country.name  geo_information  \ 0  tuxnq0fhvtk2njy  aguascalientes         mx       mexico              nan 1  tuxnq0fhvtk2njy  aguascalientes         mx       mexico              nan     geo_information.location.latitude  geo_information.location.longitude  \ 0                                nan                                 nan 1                          21.701155                          -102.31439                     id                                               name  \ 0    tuxnqkfhvunbtta0                                campestre 1a. secc. 1  tuxntuxnqkfhvtnosg  aeropuerto aguascalientes (lic. jesus teran pe...            state.id      state.name subneighborhoods 0  tuxnuefhvtmwnje  aguascalientes               [] 1  tuxnuefhvtmwnje  aguascalientes               [] 

(however, leave subneighborhoods intact, not want)


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -