我有一个数据框,其中一些值是空列表,其他值是dict列表。像这样:
0 [{'text': 'Improvement in steam-engine side-va... [] [] [{'text': '@einen tetes strut ffice. IMPROV...
1 [{'text': 'Gate.', 'language': 'en', 'truncate... [] [] [{'text': 'No. 645,359. Patented Mar. 13, I900...
2 [{'text': 'Overseaming sewing-machine.', 'lang... [] [] [{'text': 'No. 64 5,8l5. Patented Mar. 20, I90...
我想将dict列表中的值更改为列表中第一个dict的一个值。 我本想做这样的事情:
df.loc[df!=[]] = df[0]['text']
这显然不起作用
因此,考虑到这个玩具数据框:
您可以这样做:
或者,您可以像这样迭代和更新值:
改进Laurent的优秀答案,使用dataframe功能一行解决问题:
相关问题 更多 >
编程相关推荐