python - 如何提取元组的第一个元素,它是 Python 数据框中的一列?
问题描述
我有一个如下的数据框,
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 得到这个吗?提前致谢
解决方案
只需使用 pandasstr
访问器 +.get
df['senti_score'].str[0]
或者
df['senti_score'].str.get(0)
推荐阅读
- javascript - 来自 multivariate-normal-js 的确定性样本
- c - 使用多个文件打印字符串
- c++ - 在osx上将一对插入多图
- firebase - (Firebase)Firestore 安全规则 - 如果在没有自定义令牌的情况下验证电子邮件,是否允许?
- java - java 只读字符由 System.in
- python - Python:使用芹菜处理多个服务器上的参数列表
- perl - EnsEMBL Perl API 连接错误
- java - Java 多态性:为什么会返回错误?
- mysql - Rails 5 Left Outer Join 与 WHERE 查询相结合
- java - 如何从 CMD 读取所有输出以获取日志