- 行1_1368083_US_PBPR_STD
- 第215_1368083_US_PBPR_ENH
- 行216_60902413_US_PBPR_ENH
- 行227_37758281_US_PBPR_ENH
最终输出只能是列中的1368083个数字
最佳答案
使用str.split
s1 = "Row1_1368083_US_PBPR_STD"
s2 ="Row215_1368083_US_PBPR_ENH"
print(s1.split("_")[1])
print(s2.split("_")[1])
输出:
1368083
1368083
或正则表达式。
import re
s1 = "Row216_60902413_US_PBPR_ENH"
s2 ="Row227_37758281_US_PBPR_ENH"
print(re.findall(r"\d{6,}", s1)[0])
print(re.findall(r"\d{6,}", s2)[0])
关于python - 如何使用 python 脚本或 Shell 拆分或切片 CSV 文件中列内的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51588641/