-4

I have this below text and I am trying to remove the special character shown in the image using Python.

enter image description here

Update (pasting the text):

145,Kevin,07/06/2018 15:12:37,Kevin,nan,nan,"have to clear outstanding tasks. 
check schedule "

I tried the below but had no luck

DF['col'] = re.sub("[^a-zA-Z]", " ", str(DF['col']))

Could anyone assist on this. Thanks..

Kevin Nash
  • 1,511
  • 3
  • 18
  • 37

3 Answers3

0

I think you just missed out a +

try

DF['col'] = re.sub("[^A-Za-z0-9]+", " ", str(DF['col']))
Henry Yik
  • 22,275
  • 4
  • 18
  • 40
0
import re,string
s='145,Kevin,07/06/2018 15:12:37,Kevin,nan,nan,"have to clear outstanding tasks. ♔ \ncheck schedule '
punc=re.escape(string.punctuation)
re.sub(fr"[^\w\s{punc}]","",s)
Out:
'145,Kevin,07/06/2018 15:12:37,Kevin,nan,nan,"have to clear outstanding tasks.  \ncheck schedule '
kantal
  • 2,331
  • 2
  • 8
  • 15
0
df['col'] = re.sub('[^A-Za-z0-9]+',' ',str(df['col'])

If you want to apply the function to all the rows, you might do:

df['col'] = df['col'].map(lambda x: re.sub('[^A-Za-z0-9]+',' ',str(df['col'])))
Sha Li
  • 435
  • 1
  • 6
  • 13