VOOZH about

URL: https://www.geeksforgeeks.org/pandas/split-a-string-into-columns-using-regex-in-pandas-dataframe/

⇱ Split a String into Columns using Regex in Pandas DataFrame - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Split a String into Columns using Regex in Pandas DataFrame

Last Updated : 3 Feb, 2026

Given a dataset where multiple attributes are combined in a single string column, extract the individual values and split them into separate columns in a Pandas DataFrame using regex. For Example:

Input: "A: 0 B: 1 C: 2"
Output: A B C
0 1 2

Below is the Sample DataFrame used in this article:


Output
 movie_data
0 The Godfather 1972 9.2
1 Bird Box 2018 6.8
2 Fight Club 1999 8.8

Now, Let's explore different methods to split a string into columns using Regex.

Using Series.str.extract()

This method uses regex groups to pull parts of each string into separate columns. Each captured group becomes one DataFrame column.

Output

👁 Image

Explanation:

  • str.extract(): searches for the pattern in each row of the Series.
  • Regex patterns capture the Name, Year, and Rating directly.

Using str.extract() with Named Groups

This method extracts values using extract() and creates column names directly from the regex. The (?P<name>) syntax assigns column labels automatically.

Output

👁 d1
Snapshort of the output

Explanation:

  • (?P<column_name>pattern): assigns a name to each captured group.
  • Column names are created automatically from the regex.

Using str.split()

This method splits the string using str.split() at regex positions into multiple parts. expand=True turns the split parts into separate columns.

Output

👁 d2
Snapshort of the output

Explanation:

  • Regex is used to split before the year and rating.
  • expand=True converts the split result into columns.

Using re.findall() with apply()

This method finds all regex matches row-by-row using apply(). The results are converted into columns using a DataFrame.

Output

👁 d2
Snapshort of the output

Explanation:

  • re.findall(): returns all matching parts of the string.
  • apply(): processes each row individually.

Related Articles:

Comment
Article Tags:

Explore