我有以下dict,我转换为dataframe
CREATE INDEX ON :Writer(id);
CREATE INDEX ON :Songs(SongId);
结果输出
但是我希望用以下行
来映射列players_info = {'Afghanistan': {'Asghar Stanikzai': 809.0,
'Mohammad Nabi': 851.0,
'Mohammad Shahzad': 1713.0,
'Najibullah Zadran': 643.0,
'Samiullah Shenwari': 774.0},
'Australia': {'AJ Finch': 1082.0,
'CL White': 988.0,
'DA Warner': 1691.0,
'GJ Maxwell': 822.0,
'SR Watson': 1465.0},
'England': {'AD Hales': 1340.0,
'EJG Morgan': 1577.0,
'JC Buttler': 985.0,
'KP Pietersen': 1176.0,
'LJ Wright': 759.0}}
pd.DataFrame(players_info)
我尝试了Player Team Score
Mohammad Nabi Afghanistan 851.0
Mohammad Shahzad Afghanistan 1713.0
Najibullah Zadran Afghanistan 643.0
JC Buttler England 985.0
KP Pietersen England 1176.0
LJ Wright England 759.0
,但它没有按照我的意愿行事。我怎么能这样做?
答案 0 :(得分:3)
你需要:
df = df.stack().reset_index()
df.columns=['Player', 'Team', 'Score']
df.head(5)
的输出:
Player Team Score
0 AD Hales Score 1340.0
1 AJ Finch Team 1082.0
2 Asghar Stanikzai Player 809.0
3 CL White Team 988.0
4 DA Warner Team 1691.0
答案 1 :(得分:2)
让我们使用tASSOC
对此进行抨击。应该很快。
melt