Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can i remove punctuation except ! and ? in sentiment analysis in text mining using python

I am working on a text mining project in sentiment analysis. some sentence makes better sense when they have ! and ?. I am using a regular expression technique

text = re.sub("[^a-zA-Z]".format(a), ' ', text)

where text is a list of strings.

with this, all punctuations are removed, but I would like to keep ! and ? and remove the rest.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can include the ? and ! characters in your regular expression:

text = re.sub("[^a-zA-Z!?]".format(a), ' ', text)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading