JavaScript
x
2
1
a = "Other (please specify) (What were you trying to do on the website when you encountered ^f('l1')^?Âxa0)"
2
There are many values starting with ‘^f’ and ending with ‘^’ in a pandas column. And I need to replace them like below :
JavaScript
1
2
1
"Other (please specify) (What were you trying to do on the website when you encountered THIS ISSUE?Âxa0)"
2
Advertisement
Answer
You don’t mention what you’ve tried already, nor what the rest of your DataFrame looks like but here is a minimal example:
JavaScript
1
9
1
# Create a DataFrame with a single data point
2
df = pd.DataFrame(["... encountered ^f('l1')^?Âxa0)"])
3
4
# Define a regex pattern
5
pattern = r'(^f.+^)'
6
7
# Use the .replace() method to replace
8
df = df.replace(to_replace=pattern, value='TEST', regex=True)
9
Output
JavaScript
1
3
1
0
2
0 encountered TEST? )
3