The list to convert to a df:
final_list = [{'ID1':{'word':'4', 'talk': '4}}, {'ID2': {'cat':'3', 'dog': '3'}}, {'ID3': {'potatoes':'8', 'height': '6'}}]
Intended output
Word Number Category
0 word 4 ID1
1 talk 4 ID1
2 cat 3 ID2
3 dog 3 ID2
4 potatoes 8 ID3
5 height 6 ID3
I had already created a dataframe where I was able to get the desired columns of Word and Number. And from this dataframe, I am trying to add the 'Category' keys of final_list as a third column. This clearly does not work because I only get the last key element when looping. This is just to show my train of thought.
My coding attempt
df = pd.DataFrame([(a, b) for item in another_list for a, b in item.items()],
columns=['Word','Number'])
## add the last desired column (failed attempt)
for item in final_list:
for k,v in item.items():
df_events["Category"] = k