I am appending a column in data-frame column name = 'Name' which is a string comprising of a few different columns concatenation.
Now, I want to replace certain characters with certain values. Lets say
& -> and < -> less than
-> greater than ' -> this is an apostrophe " -> this is a double quotation
Now how can I efficiently apply this regex on entire column. Also, Can I put it in certain function as I need to apply the same in 4 other columns as well.
I tried this
df = pd.DataFrame({'A': ['bat<', 'foo>', 'bait&'],
'B': ['abc', 'bar', 'xyz']})
df.replace({'A': r'<','A':r'>','A':r'&'}, {'A': 'less than','A': 'greater than','A': 'and'}, regex=True, inplace=True)
I am expecting this
A B
0 batless than abc
1 foogreater than bar
2 baitand xyz
But this happened.
A B
0 bat< abc
1 foo> bar
2 baitand xyz