Try this:
data['q3'] = data['q3'].str.replace('[', '').replace(']','')
Answer from cteljr on Stack OverflowGeeksforGeeks
geeksforgeeks.org โบ python โบ replace-characters-in-strings-in-pandas-dataframe
Replace Characters in Strings in Pandas DataFrame - GeeksforGeeks
July 23, 2025 - We can replace characters using str.replace() method is basically replacing an existing string or character in a string with a new one. we can replace characters in strings is for the entire dataframe as well as for a particular column.
Stack Overflow
stackoverflow.com โบ questions โบ 28986489 โบ how-to-replace-text-in-a-string-column-of-a-pandas-dataframe
python - How to replace text in a string column of a Pandas dataframe? - Stack Overflow
I have a column in my dataframe like this: range "(2,30)" "(50,290)" "(400,1000)" ... and I want to replace the , comma with - dash. I'm currently using this method ...
DataScientYst
datascientyst.com โบ replace-text-pandas-dataframe-column
How to Replace Text in a Pandas DataFrame Or Column
November 2, 2021 - Replace text is one of the most popular operation in Pandas DataFrames and columns. In this post we will see how to replace text in a Pandas. The short answer of this questions is: (1) Replace character in Pandas column df['Depth'].str.replace('.',',') (2) Replace text in the whole
Pandas
pandas.pydata.org โบ docs โบ reference โบ api โบ pandas.DataFrame.replace.html
pandas.DataFrame.replace โ pandas 3.0.6 documentation
For a DataFrame a dict can specify that different values should be replaced in different columns. For example, {'a': 1, 'b': 'z'} looks for the value 1 in column โaโ and the value โzโ in column โbโ and replaces these values with whatever is specified in value.
Erikrood
erikrood.com โบ Python_References โบ find_replace_col.html
Finding and replacing characters in Pandas columns
import pandas as pd import numpy as np ยท raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70]} df = pd.DataFrame(raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']) df ยท df.columns = [x.strip().replace('_', '_TEST_') for x in df.columns] df.head()
IncludeHelp
includehelp.com โบ python โบ pandas-replace-a-character-in-all-column-names.aspx
Python - Pandas replace a character in all column names
July 30, 2022 - To replace a character in all column names in pandas DataFrame, you can use the df.columns.str.replace() method by specifying the old and new character to be replaced as the parameters of the function.
Pandas
pandas.pydata.org โบ docs โบ reference โบ api โบ pandas.Series.str.replace.html
pandas.Series.str.replace โ pandas 3.0.6 documentation
Replace each occurrence of pattern/regex in the Series/Index. Equivalent to str.replace() or re.sub(), depending on the regex value. ... String can be a character sequence or regular expression.
InterviewQs
interviewqs.com โบ ddi-code-snippets โบ find-replace-col
Find and replace characters in Pandas dataframe columns - InterviewQs
A step-by-step Python code example that shows how to find and replace characters in a Pandas DataFrame column header. Provided by InterviewQs, a mailing list for coding and data interview problems.
Top answer 1 of 3
144
Use str.replace:
df.columns = df.columns.str.replace("[()]", "_", regex=True)
Sample:
df = pd.DataFrame({'(A)':[1,2,3],
'(B)':[4,5,6],
'C)':[7,8,9]})
print (df)
(A) (B) C)
0 1 4 7
1 2 5 8
2 3 6 9
df.columns = df.columns.str.replace(r"[()]", "_", regex=True)
print (df)
_A_ _B_ C_
0 1 4 7
1 2 5 8
2 3 6 9
2 of 3
4
Older pandas versions don't work with the accepted answer above. Something like this is needed:
df.columns = [c.replace("[()]", "_") for c in list(df.columns)]
Top answer 1 of 2
13
replace looks for exact matches (by default unless you pass regex=True but you will need to escape the parentheses - see @piRSquared's answer), you want str.replace:
SF['NewPhone'] = SF['Phone'].str.replace("(",'xxx')
which will replace all occurrences of the passed in string with the new string
Example:
In[20]:
df = pd.DataFrame({'phone':['(999)-63266654']})
df
Out[20]:
phone
0 (999)-63266654
In[21]:
df['phone'].str.replace("(",'xxx')
Out[21]:
0 xxx999)-63266654
Name: phone, dtype: object
If we try replace then no match occurs:
In[22]:
df['phone'].replace("(",'xxx')
Out[22]:
0 (999)-63266654
Name: phone, dtype: object
See @piRSquared's answer for how to get replace to work as expected (I don't want to cannibalise his answer)
2 of 2
5
The Series.replace method takes a regex argument that is False by default. Set it to True. Also, if the string to be replaced is interpreted as a regex pattern, we'll need to escape the opening parenthesis.
df.phone.replace("\(", 'xxx', regex=True)
0 xxx999)-63266654
Name: phone, dtype: object
Setup from @EdChum
df = pd.DataFrame({'phone':['(999)-63266654']})
GeeksforGeeks
geeksforgeeks.org โบ data analysis โบ python-pandas-dataframe-replace
Python | Pandas dataframe.replace() - GeeksforGeeks
Pandas dataframe.replace() function is used to replace a string, regex, list, dictionary, series, number, etc. from a Pandas Dataframe in Python.
Published: July 11, 2025