0

This is an incredibly basic question but after reading through Stack and the documentation for str.replace, I'm not finding the answer. Trying to drop all of the punctuation in a column. What would be the proper syntax for this?

This works but it's absurd: igog['text']=igog['text'].str.replace(",","").str.replace("/","").str.replace(".","").str.replace("\"","").str.replace("?","").str.replace(";","")

This doesn't: igog['text'] = igog['text'].str.replace({","," ","/","",".","","\"","","?","",";",""}).

Because I keep getting "replace() missing 1 required positional argument: 'repl'".

Thanks in advance!

1
  • 1
    Use regular expression igog['text'].str.replace("[,/.\?;]", "") Commented Apr 27, 2021 at 21:15

1 Answer 1

2

You can make a simple loop like this:

t=",/.\?;"
for i in t:
   igog[text]=igog[text].replace(i,"")

or you can use regex:

igog['text'].str.replace("[,/.\?;]", "")

or you can use re.sub():

import re
igog['text'] = re.sub('[,/.\?;]', "", igog['text'])

or you can define a translation table :

igog['text'].translate({ord(ch):' ' for ch in ',/.\?;'})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.