I want to convert several dictionaries into rows for an excel file. I'm super close but I can't figure out how to display it well. Currently, I have this:
import pandas as pd
lst_of_dict = []
test_dict = {'Name':'Tom', 'Age':20, 'favorite_movie_2020':{'Harry Potter':20, 'Fake Movie':20, 'Cinderella':10, 'Hollywood':20}, 'favorite_movie_2021':{'Harry Potter': 21, 'Fake Movie': 20, 'Cinderella': 10, 'Holywood': 20}}
test_dict2 = {'Name':'Oliver', 'Age':40, 'favorite_movie_2020':{'Harry Potter': 30, 'Fake Movie': 50, 'Cinderella': 90, 'Hollywood': 20}}
lst_of_dict.append(test_dict)
lst_of_dict.append(test_dict2)
print(lst_of_dict)
pd.DataFrame(lst_of_dict).to_excel('output2.xlsx')
You can see how for favorite_movie I have a dictionary and it's not the easiest to read especially since I will have entries with significantly more years pairs for favorite movies. I was thinking of doing what I have for the second table in that excel sheet where I would pivot the right side only of that table but I have not been able to do that with the dictionary at all. I would appreciate any help! (If you think I should display that data some other way I'm all ears!
