I'm looking forward to iterating through both my keys here(models and dealers) and recording that in a csv. Maybe because i'm new to py or the way i'm used to like in sql, i'm not quite getting the idea of looping through two keys and getting the data. currently i'm doing a basic loop to extract the data, Any insight on how to address this would be really helpful
My code:
for x in data['models']:
for y in data['models'][x]:
fetch={'brand': x, 'model':y}
resul.append(fetch)
for a in data['dealers']:
for b in data['dealers'][a]:
fetch={'brand': a, 'dealer':b}
My input:
data={
"models" :
{
"ford" : [ "ranger","mustang","ecosport","ikon"],
"nissan" : ["gt","terrano"],
"tesla" : ["cyber truck","model x","model s","model s2"],
"honda" : ["civic", "accord"]
},
"dealers":
{
"tesla": [ "california", "newyork", "ohio"],
"ford" : ["new jersey","hongkong","beijing","delhi","telaviv","ottawa"],
"gm" : ["new york","washington dc"],
"nissan" : ["dubai","saudi arabia"]
}
}
Output:
| brand | models | dealers|
|-------|--------|---------|
|ford | ranger | new jery|
|ford | mustang| hongkong |
|ford | ecosport| beijing |
|ford | ikon | delhi|
|ford | | telaviv |
|ford | | ottawa |
|nissan | gt | dubai |
|nissan | terrano | saudi arabia|
|tesla |cyber truck| california|
|tesla | model x | newyork |
|tesla | model s | ohio |
|tesla | model s2 | |
|honda | civic | |
|honda | accord | |
|gm | new york | |
|gm | washington dc| |