VOOZH about

URL: https://www.geeksforgeeks.org/python/extract-punctuation-from-the-specified-column-of-dataframe-using-regex/

⇱ Extract punctuation from the specified column of Dataframe using Regex - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Extract punctuation from the specified column of Dataframe using Regex

Last Updated : 15 Jul, 2025

Prerequisite: Regular Expression in Python

In this article, we will see how to extract punctuation used in the specified column of the Dataframe using Regex.

Firstly, we are making regular expression that contains all the punctuation: [!"\$%&\'()*+,\-.\/:;=#@?\[\\\]^_`{|}~]* Then we are passing each row of specific column to re.findall() function for extracting the punctuation and then assigning that extracted punctuation to a new column in a Dataframe.

re.findall() function is used to extract all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found.

Syntax: re.findall(regex, string) 

Return: All non-overlapping matches of pattern in string, as a list of strings.

Now, Let's create a Dataframe:

Output:

👁 Image

Now, Extracting the punctuation from the column comment:

Output:

👁 Image
Comment