Suppose I have the following two 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 I want to create a table 'locations' with the next columns:
locations = pandas.DataFrame(columns=['city_id', 'city_name', 'name', 'latitud', 'longitud', 'country_id', 'country_name', 'state_id', 'state_name', 'subneighborhoods', 'id'])
Expect to have the following data:
I expect to have the 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' the geo_information is None, I can not create the table. How con I solve this issue?
Thanks!
json, those are dictionaries. They can easily be serialized into json withjson.dumps(a).pandas.DataFrame, I suspect the OP does not want to serialize the dictionaries.subneighborhoodsis a list, how does the data in it looks like? What do you expect the relevant column in locations to contain?