I have a list of dictionaries:
fruit_list = [
{
"id": 1,
"fruit": {
"parent_id": 1,
"name": "Banana",
"origin": "Brazil"
}
},
{
"id": 2,
"fruit": {
"parent_id": 1,
"name": "Banana",
"plural_name": "Bananas",
"origin": "Africa"
}
},
{
"id": 3,
"fruit": {
"parent_id": 2,
"name": "Orange",
"origin": "Africa"
}
},
{
"id": 4,
"fruit": {
"parent_id": 2,
"name": "Orange",
"origin": "Africa"
}
},
{
"id": 5,
"fruit": {
"parent_id": 3,
"name": "Apple",
"plural_name": "Apples",
"origin": "Africa"
}
},
{
"id": 6,
"fruit": {
"parent_id": 3,
"name": "Apple",
"plural_name": "Apples",
"origin": "Brazil"
}
}
]
I want to create a pandas dataframe out of it that looks like this:
parent_id Brazil Africa
---------------------------------
1 Banana Banana
1 Bananas
2 Orange Orange
3 Apple Apple
3 Apples Apples
It should be able to put out the plural name and add the parent id for that fruit. The problem I am having is that I am only able to get out the "normal" name. Anyone have any tips on doing this in a dynamic and elegant way? Maybe getting the fruits based on their parent ids?