用法:
Series.str.findall(pat, flags=0)
在系列/索引中查找所有出现的模式或正则表达式。
相当于将
re.findall()
应用于系列/索引中的所有元素。- pat:str
模式或正则表达式。
- flags:整数,默认 0
re
模块中的标志,例如re.IGNORECASE
(默认为 0,表示没有标志)。
- 字符串列表的系列/索引
此系列/索引的每个字符串中的模式或正则表达式的所有非重叠匹配。
参数:
返回:
例子:
>>> s = pd.Series(['Lion', 'Monkey', 'Rabbit'])
搜索模式“Monkey”会返回一个匹配项:
>>> s.str.findall('Monkey') 0 [] 1 [Monkey] 2 [] dtype:object
另一方面,模式“MONKEY”的搜索不返回任何匹配:
>>> s.str.findall('MONKEY') 0 [] 1 [] 2 [] dtype:object
可以将标志添加到模式或正则表达式中。例如,要找到忽略大小写的模式“MONKEY”:
>>> import re >>> s.str.findall('MONKEY', flags=re.IGNORECASE) 0 [] 1 [Monkey] 2 [] dtype:object
当模式匹配 Series 中的多个字符串时,返回所有匹配项:
>>> s.str.findall('on') 0 [on] 1 [on] 2 [] dtype:object
也支持正则表达式。例如,搜索以单词‘on’ 结尾的所有字符串如下所示:
>>> s.str.findall('on$') 0 [on] 1 [] 2 [] dtype:object
如果在同一个字符串中多次找到该模式,则返回多个字符串的列表:
>>> s.str.findall('b') 0 [] 1 [] 2 [b, b] dtype:object
相关用法
- Python pandas.Series.str.isdecimal用法及代码示例
- Python pandas.Series.str.get用法及代码示例
- Python pandas.Series.str.replace用法及代码示例
- Python pandas.Series.str.endswith用法及代码示例
- Python pandas.Series.str.isspace用法及代码示例
- Python pandas.Series.str.isdigit用法及代码示例
- Python pandas.Series.str.wrap用法及代码示例
- Python pandas.Series.str.isalnum用法及代码示例
- Python pandas.Series.str.zfill用法及代码示例
- Python pandas.Series.str.partition用法及代码示例
- Python pandas.Series.str.isnumeric用法及代码示例
- Python pandas.Series.str.startswith用法及代码示例
- Python pandas.Series.str.count用法及代码示例
- Python pandas.Series.str.rpartition用法及代码示例
- Python pandas.Series.str.strip用法及代码示例
- Python pandas.Series.str.removesuffix用法及代码示例
- Python pandas.Series.str.rsplit用法及代码示例
- Python pandas.Series.str.islower用法及代码示例
- Python pandas.Series.str.removeprefix用法及代码示例
- Python pandas.Series.str.len用法及代码示例
注:本文由纯净天空筛选整理自pandas.pydata.org大神的英文原创作品 pandas.Series.str.findall。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。