Python | Pandas Series.str.extract() Last Updated : 11 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Series.str can be used to access the values of the series as strings and apply several methods to it. Pandas Series.str.extract() function is used to extract capture groups in the regex pat as columns in a DataFrame. For each subject string in the Series, extract groups from the first match of regular expression pat. Syntax: Series.str.extract(pat, flags=0, expand=True) Parameter : pat : Regular expression pattern with capturing groups. flags : int, default 0 (no flags) expand : If True, return DataFrame with one column per capture group. Returns : DataFrame or Series or Index Example #1: Use Series.str.extract() function to extract groups from the string in the underlying data of the given series object. Python # importing pandas as pd import pandas as pd # importing re for regular expressions import re # Creating the Series sr = pd.Series(['New_York', 'Lisbon', 'Tokyo', 'Paris', 'Munich']) # Creating the index idx = ['City 1', 'City 2', 'City 3', 'City 4', 'City 5'] # set the index sr.index = idx # Print the series print(sr) Output : Now we will use Series.str.extract() function to extract groups from the strings in the given series object. Python # extract groups having a vowel followed by # any character result = sr.str.extract(pat = '([aeiou].)') # print the result print(result) Output : As we can see in the output, the Series.str.extract() function has returned a dataframe containing a column of the extracted group. Example #2 : Use Series.str.extract() function to extract groups from the string in the underlying data of the given series object. Python # importing pandas as pd import pandas as pd # importing re for regular expressions import re # Creating the Series sr = pd.Series(['Mike', 'Alessa', 'Nick', 'Kim', 'Britney']) # Creating the index idx = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5'] # set the index sr.index = idx # Print the series print(sr) Output : Now we will use Series.str.extract() function to extract groups from the strings in the given series object. Python # extract groups having any capital letter # followed by 'i' and any other character result = sr.str.extract(pat = '([A-Z]i.)') # print the result print(result) Output : As we can see in the output, the Series.str.extract() function has returned a dataframe containing a column of the extracted group. Comment More infoAdvertise with us Next Article Python | Pandas Series.str.extractall() S Shubham__Ranjan Follow Improve Article Tags : Pandas Python-pandas Python-pandas-series-str AI-ML-DS With Python Similar Reads Python | Pandas Series.str.extractall() Series.str can be used to access the values of the series as strings and apply several methods to it. Pandas Series.str.extractall() function is used to extract capture groups in the regex pat as columns in a DataFrame. For each subject string in the Series, extract groups from all matches of regula 2 min read Python | Pandas series.str.get() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.get() method is used to get element at the passed position. This method wor 3 min read Python | Pandas series.str.get() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.get() method is used to get element at the passed position. This method wor 3 min read Python | Pandas Series.str.center() Series.str can be used to access the values of the series as strings and apply several methods to it. Pandas Series.str.center() function is used for filling left and right side of strings in the Series/Index with an additional character. The function is equivalent to Python's str.center(). Syntax: 3 min read Python | Pandas Series.str.index() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.index() method is used to search and return lowest index of a substring in 3 min read Python | Pandas Series.str.index() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.index() method is used to search and return lowest index of a substring in 3 min read Like