我有一个很大的文本文件,我想只提取某些短语/单词后面的数字。
这个巨大的文本文件中有几十行,格式如下:
汽车的最佳 CV 模型:15778 的顺序:2 阈值:0,AUC 为:0.7185 基因 aau_roc:0.466281
一种解决方案是只查看“for car: X”、“is order: X”、“threshold: X”、“Ygene aau_roc: X”之后的数字!
最后我希望每行有 15778, 2, 0, 0.7185, 0.466281。
>>> if line.startswith('Best CV Model'):
... re.findall(r'\d+\.{0,1}\d*', line)
...
['15778', '2', '0', '0.7185', '0.466281']
Run Code Online (Sandbox Code Playgroud)