【发布时间】:2020-10-20 14:05:07
【问题描述】:
输入数据框:
Id Score Score1
0 19138359 0.5347029367015973 0.832428474443
1 12134001 0.9347094453553113 0.632535428479
以下数据框想要作为输出:
Id Scores
0 19138359 {'Score': 0.5347029367015973, 'Score1': 0.832428474443}
1 12134001 {'Score': 0.9347094453553113, 'Score1': 0.632535428479}
Scores = ['Score', 'Score1']
d, l = {}, []
for i, row in publish.iterrows():
d['Id'] = row['Id']
d['Scores'] = row[Scores].to_dict()
l.append(d)
输出错误!
【问题讨论】:
标签: python python-3.x pandas dataframe dictionary