I have a column in my pandas Dataframe df that contains a string with some trailing hex-encoded NULLs (\\x00). At least I think that it\'s that. When I tried to replace them wit
You did not specify a regex or require an exact match, hence str.replace worked
str.replace(old, new[, count])
Return a copy of the string with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.
DataFrame.replace(to_replace=None, value=None, inplace=False, limit=None, regex=False, method='pad', axis=None)
parameter: to_replace : str, regex, list, dict, Series, numeric, or None
str or regex: str: string exactly matching to_replace will be replaced with value regex: regexs matching to_replace will be replaced with value
They're not actually in the string: you have unescaped control characters, which Python displays using the hexadecimal notation:
remove all non-word characters in the following way:
re.sub(r'[^\w]', '', '\x00\x00\x00\x08\x01\x008\xe6\x7f')