Python | Pandas Series.str.findall()
str.findall()
method is also used to find substrings or separators in each string in a series. But it is different from str.find() method. Instead of returning the index, it returns list with substrings and size of list is number of times it occurred.
Syntax: Series.str.findall(pat, flags=0) Parameters: pat: Substring to be searched for flags: Regex flags that can be passed (A, S, L, M, I, X), default is 0 which means None. For this regex module (re) has to be imported too. Return Type: Series of list(strings).
To download the CSV used in code, click here.
In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below.

# importing pandas module
import pandas as pd
# making data frame
data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv")
# removing null values to avoid errors
data.dropna(inplace = True)
# string to be searched for
search ='r'
# returning values and creating column
data["Findall(name)"]= data["Name"].str.findall(search)
# display
data.head(10)

# importing pandas module
import pandas as pd
# importing regex module
import re
# making data frame
data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv")
# removing null values to avoid errors
data.dropna(inplace = True)
# string to be searched for
search ='a'
# returning values and creating column
data["Findall(name)"]= data["Name"].str.findall(search, flags = re.I)
# display
data.head(10)
