Remove Punctuation

Goal

This post aims to introduce how to remove punctuation using string.

Reference

Libraries

In [9]:
import string

Create a document

In [10]:
documents = ["this isn't a sample.", 
            'this is another example.' ,
            'this" also appears in the second example.'
            'Is this an example?']

documents
Out[10]:
["this isn't a sample.",
 'this is another example.',
 'this" also appears in the second example.Is this an example?']

Remove Punctuation

In [11]:
table = str.maketrans('', '', string.punctuation)
doc_removed_punctuation = [w.translate(table) for w in documents]
doc_removed_punctuation
Out[11]:
['this isnt a sample',
 'this is another example',
 'this also appears in the second exampleIs this an example']

Comments

Comments powered by Disqus