python - 如何使用 python 脚本或 Shell 拆分或切片 CSV 文件中列内的文本?

标签 python linux shell

  1. 行1_1368083_US_PBPR_STD
  2. 第215_1368083_US_PBPR_ENH
  3. 行216_60902413_US_PBPR_ENH
  4. 行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/

相关文章:

python - Sklearn 的 MinMaxScaler 只返回零

Linux 内核 : How to capture a key press and replace it with another key?

java - 将 Java 应用程序绑定(bind)到接口(interface)

android - insmod : init_module failed (Exec format error)

linux - 并行和顺序脚本执行

node.js - 如何检测 Node 的 process.stdout 是否正在通过管道传输?

linux - cp 命令不在 sh\bash 脚本中创建目录,为什么?

python - Socket收不到数据?客户端是使用 Boost.asyio 库编写的。服务器是用python写的

python - 在 docker 容器之间共享 gensim 的 KeyedVectors 对象的内存

Python:做点什么然后 sleep ,重复