I am trying to create a pandas multi-indexed DataFrame from a double-nested dictionary but am quite stumped as to how to do this.
As some background I have scraped some data from a website and put it into this nested dictionary form as I thought it would be easiest to work with (but I appear to be wrong :D)…
The nested dictionary currently looks like this and I want to put this into a DataFrame that has the ID
of the fighter as the column so that in the case of multiple fighters, each column would represent a new fighter, the fight number
(0
or 1
in this example as the first row index) with the inner level being the fight details
(e.g., date
, fighter weight
etc).
{'ID': {0: {'date ↕': '2024-05-23',
'Fighter Weight': '',
'Opponent': 'fighter_1',
'Opponent Weight': '',
'w-l-d': ('11', '0', '0'),
'result': 'VS',
'rounds': '12'},
1: {'date ↕': '2022-08-28',
'Fighter Weight': '227¾',
'Opponent': 'Fighter_2',
'Opponent Weight': '211',
'result': 'W-SD',
'rounds': '12/12'}}}
On the initial run when I ran DataFrame.from_dict(data)
this yields an output where the values of the DataFrame is the inner dictionary.
479205
0 {'date ↕': '2024-05-18', 'Fighter Weight': '',...
1 {'date ↕': '2023-10-28', 'Fighter
If you think it would be better to store the data into something other than a nested dictionary then also please let me know as I am open to making changes to the scraper as well.
Thanks so much!
1