df.at[0, 'A'] = [{'score': 12, 'player': [{'name': 'Jacob', 'score': 2},
{'name': 'Shane', 'score': 5}, ...]},
{'score': 33, 'player': [{'name': 'Cindy', 'score': 4}, ...]}, ...]
Say I have a list of n dictionaries for column 'A' in a data frame like above. I want to add a new key named 'game' which is the index of the list. So, it'd be like below.
df.at[0, 'A'] = [{'score': 12, 'player': [...], 'game': 0},
{'score': 33, 'player': [...], 'game': 1}, ...]
Since I have to do the same thing with 'player', I don't want to use for
loops.
Is there a way to achieve this?
df.at[0, 'A'][0]['player'] = [{'name': 'Jacob', 'score': 2, 'number': 0},
{'name': 'Shane', 'score': 5, 'number': 1}, ...]}
For example, 'player' will have key 'number' whose value is the index of the inner list.
Basically, I don't want to use any nested for
loop to do this because the actual data I have received is a way larger NL data that actually came in that ridiculous form.