本文簡要介紹
pyspark.pandas.Series.str.findall
的用法。用法:
str.findall(pat: str, flags: int = 0) → ps.Series
查找係列中所有出現的模式或正則表達式。
相當於將
re.findall()
應用於係列中的所有元素。- pat:str
模式或正則表達式。
- flags:int,默認 0(無標誌)
re
模塊標誌,例如re.IGNORECASE
。
- 係列對象
此係列的每個字符串中的模式或正則表達式的所有非重疊匹配。
參數:
返回:
例子:
>>> s = ps.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 pyspark Series.str.find用法及代碼示例
- Python pyspark Series.str.join用法及代碼示例
- Python pyspark Series.str.startswith用法及代碼示例
- Python pyspark Series.str.slice_replace用法及代碼示例
- Python pyspark Series.str.rjust用法及代碼示例
- Python pyspark Series.str.lstrip用法及代碼示例
- Python pyspark Series.str.len用法及代碼示例
- Python pyspark Series.str.slice用法及代碼示例
- Python pyspark Series.str.isnumeric用法及代碼示例
- Python pyspark Series.str.endswith用法及代碼示例
- Python pyspark Series.str.swapcase用法及代碼示例
- Python pyspark Series.str.isdecimal用法及代碼示例
- Python pyspark Series.str.rstrip用法及代碼示例
- Python pyspark Series.str.istitle用法及代碼示例
- Python pyspark Series.str.match用法及代碼示例
- Python pyspark Series.str.rindex用法及代碼示例
- Python pyspark Series.str.rsplit用法及代碼示例
- Python pyspark Series.str.strip用法及代碼示例
- Python pyspark Series.str.ljust用法及代碼示例
- Python pyspark Series.str.count用法及代碼示例
- Python pyspark Series.str.title用法及代碼示例
- Python pyspark Series.str.upper用法及代碼示例
- Python pyspark Series.str.isupper用法及代碼示例
- Python pyspark Series.str.pad用法及代碼示例
- Python pyspark Series.str.repeat用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Series.str.findall。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。