Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- alphabet = string.ascii_letters+string.punctuation
- 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~'
- df.col.str.strip(alphabet).astype(bool).any()
- df = pd.DataFrame({'col1':['abc', 'hello?'], 'col2': ['ÃÉG', 'Ç']})
- col1 col2
- 0 abc ÃÉG
- 1 hello? Ç
- df.col1.str.strip(alphabet).astype(bool).any()
- False
- df.col2.str.strip(alphabet).astype(bool).any()
- True
- def strip_character(dataCol):
- r = re.compile(r'[^a-zA-Z !@#$%&*_+-=|:";<>,./()[]{}']')
- return r.sub('', dataCol)
- df[resultCol] = data[dataCol].apply(strip_character)
Add Comment
Please, Sign In to add comment