在 DataFrame 中查找第二次出现的正则表达式

时间:2021-01-10 15:20:06

标签: python regex pandas dataframe

我在数据框中有一个字符串列,我想从中提取速率,这是最后一次出现的反斜杠。

 After so many requests, this is Bretagne. She was the last surviving 9/11 search dog, and our second ever 14/10. RIP* 

我想得到 14/10

2 个答案:

答案 0 :(得分:0)

试试这个代码来获取这句话中所有日期的列表

import re
re.findall(r"\d+/\d+","After so many requests, this is Bretagne. She was the last surviving 9/11 search dog, and our second ever 14/10. RIP* ")

要获得第二个,只需选择此列表中的第二个项目

答案 1 :(得分:0)

这个正则表达式有效:

>>> s = "After so many requests, this is Bretagne. She was the last surviving 9/11 search dog, and our second ever 14/10. RIP*"
>>> re.findall("\d+/(?=[^/]*$)\d+", s)
['14/10']