我有一个数据框如下,
id text senti_score
1 text A (0.5,1)
2 text B (0.4,0.7)
3 Nan None
4 text c (0.2,0.4)
Expected output,
id text senti_score new_Score
1 text A (0.5,1) 0.5
2 text B (0.4,0.7) 0.4
3 Nan None None
4 text c (0.2,0.4) 0.2
请注意有些记录没有 senti_Score,里面只有“None”。
有人可以帮助我如何使用 python 获取它吗?提前致谢
最佳答案
只需使用 pandas str
访问器 + .get
df['senti_score'].str[0]
或
df['senti_score'].str.get(0)
关于python - 如何提取元组的第一个元素,它是 Python 数据框中的一列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55552107/