Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import string
  2. alphabet = string.ascii_letters+string.punctuation
  3.  
  4. 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~'
  5.  
  6. df.col.str.strip(alphabet).astype(bool).any()
  7.  
  8. df = pd.DataFrame({'col1':['abc', 'hello?'], 'col2': ['ÃÉG', 'Ç']})
  9.  
  10.  
  11. col1 col2
  12. 0 abc ÃÉG
  13. 1 hello? Ç
  14.  
  15. df.col1.str.strip(alphabet).astype(bool).any()
  16. False
  17. df.col2.str.strip(alphabet).astype(bool).any()
  18. True
  19.  
  20. def strip_character(dataCol):
  21. r = re.compile(r'[^a-zA-Z !@#$%&*_+-=|:";<>,./()[]{}']')
  22. return r.sub('', dataCol)
  23.  
  24. df[resultCol] = data[dataCol].apply(strip_character)
Add Comment
Please, Sign In to add comment