Find all occurrences of pattern or regular expression in the Series/Index. Equivalent to applying :func:`re.findall` to all the elements in the Series/Index. Parameters ---------- pat : str Pattern or regular expression. flags :
(self, pat, flags: int = 0)
| 3237 | |
| 3238 | @forbid_nonstring_types(["bytes"]) |
| 3239 | def findall(self, pat, flags: int = 0): |
| 3240 | """ |
| 3241 | Find all occurrences of pattern or regular expression in the Series/Index. |
| 3242 | |
| 3243 | Equivalent to applying :func:`re.findall` to all the elements in the |
| 3244 | Series/Index. |
| 3245 | |
| 3246 | Parameters |
| 3247 | ---------- |
| 3248 | pat : str |
| 3249 | Pattern or regular expression. |
| 3250 | flags : int, default 0 |
| 3251 | Flags from ``re`` module, e.g. `re.IGNORECASE` (default is 0, which |
| 3252 | means no flags). |
| 3253 | |
| 3254 | Returns |
| 3255 | ------- |
| 3256 | Series/Index of lists of strings |
| 3257 | All non-overlapping matches of pattern or regular expression in each |
| 3258 | string of this Series/Index. |
| 3259 | |
| 3260 | See Also |
| 3261 | -------- |
| 3262 | count : Count occurrences of pattern or regular expression in each string |
| 3263 | of the Series/Index. |
| 3264 | extractall : For each string in the Series, extract groups from all matches |
| 3265 | of regular expression and return a DataFrame with one row for each |
| 3266 | match and one column for each group. |
| 3267 | re.findall : The equivalent ``re`` function to all non-overlapping matches |
| 3268 | of pattern or regular expression in string, as a list of strings. |
| 3269 | |
| 3270 | Examples |
| 3271 | -------- |
| 3272 | >>> s = pd.Series(["Lion", "Monkey", "Rabbit"]) |
| 3273 | |
| 3274 | The search for the pattern 'Monkey' returns one match: |
| 3275 | |
| 3276 | >>> s.str.findall("Monkey") |
| 3277 | 0 [] |
| 3278 | 1 [Monkey] |
| 3279 | 2 [] |
| 3280 | dtype: object |
| 3281 | |
| 3282 | On the other hand, the search for the pattern 'MONKEY' doesn't return any |
| 3283 | match: |
| 3284 | |
| 3285 | >>> s.str.findall("MONKEY") |
| 3286 | 0 [] |
| 3287 | 1 [] |
| 3288 | 2 [] |
| 3289 | dtype: object |
| 3290 | |
| 3291 | Flags can be added to the pattern or regular expression. For instance, |
| 3292 | to find the pattern 'MONKEY' ignoring the case: |
| 3293 | |
| 3294 | >>> import re |
| 3295 | >>> s.str.findall("MONKEY", flags=re.IGNORECASE) |
| 3296 | 0 [] |