I want to reformat my nested dictionary before outputting it into csv. My nested dictionary:
review = {'Q1': {'Question': 'question wording','Answer': {'Part 1': 'Answer part one', 'Part 2': 'Answer part 2'} ,'Proof': {'Part 1': 'The proof part one', 'Part 2': 'The proof part 2'}},
'Q2': {'Question': 'question wording','Answer': {'Part 1': 'Answer part one', 'Part 2': 'Answer part 2'} ,'Proof': {'Part 1': 'The proof part one', 'Part 2': 'The proof part 2'}}}
So far I have tried:
my_df = pd.DataFrame(review)
my_df = my_df.unstack()
and get part way:
Q1 Answer {'Part 1': 'Answer part one', 'Part 2': 'Answe...
Proof {'Part 1': 'The proof part one', 'Part 2': 'Th...
Question question wording
Q2 Answer {'Part 1': 'Answer part one', 'Part 2': 'Answe...
Proof {'Part 1': 'The proof part one', 'Part 2': 'Th...
Question question wording
but I want it to look like this in the end:
Index Question Answer Proof
Q1 question one wording Answer part 1 Proof part 1
Q1 question one wording Answer part 2 Proof part 2
Q2 question two wording Answer part 1 Proof part 1
Q2 question two wording Answer part 2 Proof part 2
So I need to melt/unstack/pivot/expand/other_manipulation_word the nested dictionary in the Dataframe.
I have looked at this for guidance but can't apply it to my own: Expand pandas dataframe column of dict into dataframe columns