I am trying to remove certain words from a dataframe column and failing miserably...
Some of my sample data:
Stock_Name
Vanguard US Government Bond Index GBP Inc (Hedged)
Vanguard US Government Bond Index GBP Acc (Hedged)
Vanguard US Government Bond Index GBP Inc
Vanguard US Government Bond Index USD Acc
The dictionary:
replace_values = {
r'\bAcc\b': "",
r'\bInc\b': "",
r'\b(Hedged)\b': "",
r'\bGBP\b': "",
r'\bUSD\b': ""
}
df["Stock_Name"] = df["Stock_Name"].replace(replace_values,regex=True)
The output I am getting:
Vanguard US Government Bond Index ()
Vanguard US Government Bond Index ()
Vanguard US Government Bond Index
Vanguard US Government Bond Index
for some reason the parentheses are being omitted. I have tried adding '()' to my replace values dict but it doesn't seem to do anything.