Shivika Patel
Shivika Patel

Reputation: 233

Replace function is not working in pandas dataframe

I am trying to replace '?' with "'" but the question mark still remains. I am using below code to replace

df['Indication'] = df['Indication'].replace('?', '’')

The resulting column is given below:

Hodgkin?s Lymphoma at high risk of relapse or progression post-ASCT

But the output I want is the following:

Hodgkin's Lymphoma at high risk of relapse or progression post-ASCT

Upvotes: 1

Views: 45

Answers (1)

Andrej Kesely
Andrej Kesely

Reputation: 195408

Use .str.replace:

df["Indication"] = df["Indication"].str.replace("?", "'", regex=False)
print(df)

Prints:

                                          Indication
0  Hodgkin's Lymphoma at high risk of relapse or ...

Upvotes: 1

Related Questions