Here is my regex function:
def parse_repl(df_item):
for pattern, replacement in d_comp.items():
df_item = pattern.sub(replacement, df_item)
return df_item
d_comp is a compiled dictionary of regex items to replace.
I'm calling it like this:
df.apply(parse_repl)
df.to_csv(...)
I also tried apply with axis=0 and axis=1 and neither worked.
the error is this:
TypeError: ('expected string or bytes-like object', 'occurred at index myField')
Error happens in this line of the parse_repl function:
df_item = pattern.sub(replacement, df_item)
Presumably because sub expects a byte array.
The question is, how can I convert df_item to where it will work within the sub call, ie, change the item's data, and then return the changes back int the main DF intact?
Thanks!