例如,我有一個(gè)數(shù)據(jù)框df = {'dicts':[{'id': 0, 'text': 'Willamette'},{'id': 1, 'text': 'Valley'}], 'ner': ["Person", "Location"]}df= pd.DataFrame(df)` 我想要像這樣的最終結(jié)果{'id': 0, 'text': 'Willamette', 'ner': 'Person'}{'id': 1, 'text': 'Valley', 'ner': 'Location'}`我正在使用以下邏輯,但它對(duì)我不起作用-for i, rows in df["dicts"].iteritems(): for cat in df['ner']: df["dicts"][i]=df["dicts"][i].update({'ner' : df['ner'][cat]})我該如何解決這個(gè)問(wèn)題?
1 回答

叮當(dāng)貓咪
TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
IIUC
d=pd.DataFrame(df.dicts.tolist(),index=df.index).join(df[['ner']]).to_dict('r')[{'id': 0, 'text': 'Willamette', 'ner': 'Person'}, {'id': 1, 'text': 'Valley', 'ner': 'Location'}]
添加回答
舉報(bào)
0/150
提交
取消