Skip to content
Advertisement

Replace apostrophes and curly brackets with blank space in multiple columns of dataframe

I have a table (dataframe) where multiple string columns contain curly brackets and apostrophes, which I am trying to replace with a blank space:

Table

I started with the genre1 column but I keep getting a key error.

This is the code I am trying to remove curly bracket:

movies['genre1'].replace(to_replace=["}"],value="",inplace=True)

Advertisement

Answer

This will work!

movies['genre1'] = movies['genre1'].str.replace("}","")

What you are doing is will look exactly for ‘}’, and wherever the value of the cell will be exactly equal to }, it will replace. So, you need to use the attr str.

Advertisement