I was getting my data from a yml file, so I could get two lists, like this:
one of the lists, named list_products, contains the name of the product:
['ABCD'
'LTAP'
'DEFG'
'FFEE']
The other, named list_ids, contains a list of ids and sometimes the element can be a list:
[[100, 200],
[3333],
[1500,99, 870],
[2]]
When working only with list_ids, I could get a dataframe, this is the code I used:
flat_list = [item for sublist in list_ids for item in sublist]
id_df = pd.DataFrame(flat_list,columns=['id'])
And this was the result:
id
100
200
3333
1500
99
870
2
Now, I want to have a dataframe with the product name as well. I want to get this:
id name
100 'ABCD'
200 'ABCD'
3333 'LTAP'
1500 'DEFG'
99 'DEFG'
870 'DEFG'
2 'FFEE'