I'm trying to convert an array of strings in arrays of integers associating its ids in a dataframe column.
That's because I need to map a list of home rooms per id like the next shows:
That's the JSON I have to map:
[
{
"id": 1,
"name": "dining room",
},
{
"id": 2,
"name": "living room",
},
{
"id": 3,
"name": "guest room",
},
{
"id": 4,
"name": "bathroom",
},
{
"id": 5,
"name": "game room",
},
{
"id": 6,
"name": "kitchen",
},
{
"id": 7,
"name": "storage room",
},
{
"id": 8,
"name": "bedroom",
},
{
"id": 9,
"name": "family room",
}
]
That's the dataframe I have:
index home_rooms
0 [dining room, living room, bathroom]
1 [guest room, kitchen, game room]
2 [storage room, family room, bedroom]
3 [dining room, living room, bathroom]
4 [guest room, kitchen, game room]
5 [storage room, family room, bedroom]
6 [dining room, living room, bathroom]
7 [guest room, kitchen, game room]
8 [storage room, family room, bedroom]
And that's the dataframe I need:
index home_rooms
0 [1, 2, 4]
1 [3, 6, 5]
2 [7, 9, 8]
3 [1, 2, 4]
4 [3, 6, 5]
5 [7, 9, 8]
6 [1, 2, 4]
7 [3, 6, 5]
8 [7, 9, 8]
Any solution?
Thanks in advance.
home_roomin your dataframe contains the typo in the spelling ofdining, right?