player_name | awards |
---|---|
Sergei Belov | {‘2009-2010’: [‘Russia2 Silver Medal’], ‘2013-2014’: [‘VHL Silver Medal’]} |
Rafael Khakimov | {‘2010-2011’: [‘MHL All-Star Game’,’MHL Best GAA (1.79)’,’MHL Best Goaltender’,’MHL Goaltender of the Month (February)’,’MHL Goaltender of the Month (September)’],’2017-2018′: [‘VHL Playoffs Best GAA (1.39)’], ‘2021-2022’: [‘VHL Goaltender of the Month (November)’]} |
How to unpack awards in python into the column of the name of the awards and into the value of the year of the season when it was received.
Sample result:
player_name | russia2_silver_medal | mhl_allstar_game |
---|---|---|
Sergei Belov | 2009-2010 | NaN |
Rafael Khakimov | NaN | 2010-2011 |
players_personal[‘awards’] = players_personal[‘awards’].apply(lambda x: json.loads(x))
First, I converted from strings to json, and then tried to collect them into a dataframe through a loop, but not successfully
2
Answers
Here is one way. Note that I
T
transposed the data to make it visible here. You can get rid of theT
at the very endAnother version:
Prints: