I have created the following pandas dataframe:
ds = {"col1":["Mr Stuart (Acting)", "Mr Smith", "John Ross (Acting)"]}
df = pd.DataFrame(data=ds)
Which looks like this:
print(df)
col1
0 Mr Stuard (Acting)
1 Mr Smith
2 John Ross (Acting)
I want to replace
" (Acting)"
(in col1
) with nothing.
So I have written this piece of code:
df = df.replace(to_replace=" (Acting)",value="",)
But the " (Acting)" bit is still present in the resulting dataframe:
print(df)
col1
0 Mr Stuard (Acting)
1 Mr Smith
2 John Ross (Acting)
Can someone tell me why the replace
command is not working? And how can I replace " (Acting)" with nothing?