gpt4 book ai didi

python - 在文本文件中的某些单词后提取数字

转载 作者:太空宇宙 更新时间:2023-11-03 13:48:48 24 4
gpt4 key购买 nike

我有一个很大的文本文件,我想只提取某些短语/单词之后的数字。

这个巨大的文本文件中有几十行,格式如下:

Best CV Model for car: 15778 is order:2 threshold: 0 with AUC of : 0.7185 gene aau_roc: 0.466281

一个解决方案是只看“for car: X”、“is order: X”、“threshold: X”、“Y gene 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']

关于python - 在文本文件中的某些单词后提取数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13782119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com