VOOZH about

URL: https://www.geeksforgeeks.org/pandas/python-pandas-series-str-extract/

⇱ Python | Pandas Series.str.extract() - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | Pandas Series.str.extract()

Last Updated : 11 Jul, 2024

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.

Output :

👁 Image

Now we will use

Series.str.extract()

function to extract groups from the strings in the given series object.

Output :

👁 Image

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.

Output :

👁 Image

Now we will use

Series.str.extract()

function to extract groups from the strings in the given series object.

Output :

👁 Image

As we can see in the output, the

Series.str.extract()

function has returned a dataframe containing a column of the extracted group.

Comment

Explore