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
Answer from jezrael on Stack Overflow
🌐
TechOverflow
techoverflow.net › 2021 › 04 › 03 › how-to-replace-string-in-column-names-in-pandas-dataframe
How to replace string in column names in Pandas DataFrame | TechOverflow
May 8, 2026 - Use this snippet in order to replace a string in column names for a pandas DataFrame: pandas_replace_column_names.py · Copy Download · new_df = df.rename(columns=lambda s: s.replace("A", "B")) # df will not be modified ! You can also modify the column names in-place (i.e.
Discussions

python - Replace string in pandas df column name - Stack Overflow
I have a dataframe in pandas, with columns named "string_string", I'm trying to rename them by removing the "_" and the following string. For example, I want to change "12527_AC9E5" to "12527". I... More on stackoverflow.com
🌐 stackoverflow.com
November 5, 2015
How to replace column names with Pandas?
Loop through the header’s index. Within your loop, insert a conditional statement. Your loop could look something like this i = 1 For name in df.indexname loop: while i in range(highest number present in index): if str(i) in name: name.strip(i, ‘.’) The above syntax may not be perfect as I’m still learning myself. However, the logic will achieve your desired result. It looks like pandas added the numbers so the columns wouldn’t be duplicated. If they were duplicated then it wouldn’t be able to differentiate which year your wanting when you access df[‘February’]. You probably could set an option where the headers are indexed by a number and not the incoming value. If you continue to struggle just lmk! I’d be willing to help you see this problem through :) More on reddit.com
🌐 r/learnpython
10
8
January 2, 2022
python - Replace column names in a pandas data frame that partially match a string - Stack Overflow
Background I would like to identify column names in a dataframe that partially match a string, and replace them with the original names plus some new elements added to them. The new elements are More on stackoverflow.com
🌐 stackoverflow.com
June 15, 2017
Working With Missing And Duplicate Data - str.replace() problem
missing_2017.columns = missing_2017.columns.str.replace(".", " ") I am trying to replace the dots in the column names with spaces, however I get error when I run above line please advise? Also there are variable number… More on community.dataquest.io
🌐 community.dataquest.io
1
0
July 15, 2020
🌐
Quora
quora.com › How-can-I-replace-characters-in-a-multiple-column-name-in-pandas
How to replace characters in a multiple column name in pandas - Quora
To replace characters in multiple column names in pandas, use vectorized string methods on the DataFrame’s .columns (an Index) or rename with a mapping/func.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to replace string in pandas dataframe
How to Replace String in Pandas DataFrame - Spark By {Examples}
June 13, 2025 - In pandas, to replace a string in the DataFrame column, you can use either the replace() function or the str.replace() method along with lambda methods.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.6 documentation
Simple string replacement. ... Regex substitution is performed under the hood with re.sub. The rules for substitution for re.sub are the same. Regular expressions will only substitute on strings, meaning you cannot provide, for example, a regular expression matching floating point numbers and expect the columns in your frame that have a numeric dtype to be matched.
🌐
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.
Find elsewhere
🌐
Convert2f
convert2f.com › replace-column-name-in-pandas
All Results for Replace Column Name In Pandas​
Use this snippet in order to replace a string in column names for a pandas DataFrame: replace-stringcolumn-namespandas-dataframe.py 📋 Copy to clipboard ⇓ Download.
🌐
GeeksforGeeks
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.
🌐
Reddit
reddit.com › r/learnpython › how to replace column names with pandas?
r/learnpython on Reddit: How to replace column names with Pandas?
January 2, 2022 -

I'm working on a very large dataset (from an Excel document) that has the price information of 415 different products for each month since January 2003. For example, when you open the Excel document the first six months look like below.

2003 2003 2003 2003 2003 2003

January February March April May June

When I used the read_excel() method with the header parameter as follows df.read_excel(header=5), the months in 2004 are read as January.1, February.1 etc. Similarly headers for 2005 look like January.2, February.2 and so on.

When I was using a small portion of the data I just created a dictionary for the old headers as keys and new headers as values and used products.rename(columns=dict_name) but now I want to work on the whole document, which has more than 200 headers but I don't want to rename them individually.

I was wondering if there is an easy way to rename all headers with something like find and replace all that includes ".1" for 2004 for example. so that they reflect their respective years along with the months.

I tried to explain the best I could and hope I could explain what I have in my mind.

🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.5 documentation
Value to replace any values matching to_replace with. For a DataFrame a dict of values can be used to specify which value to use for each column (columns not in the dict will not be filled). Regular expressions, strings and lists or dicts of such objects are also allowed.
🌐
KDnuggets
kdnuggets.com › 2022 › 11 › 4-ways-rename-pandas-columns.html
4 Ways to Rename Pandas Columns - KDnuggets
For example, we have created a new dataframe using a dictionary and renamed the columns by providing a list of strings to column attributes. student_df_2 = pd.DataFrame(student_dict) student_df_2.columns = ["Student_ID", "First_Name", "Average_Grade"] student_df_2 · The third method is native to the Python ecosystem where we replace strings of `columns` attributes.
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-rename-columns-in-pandas-dataframe
Rename Columns in Pandas DataFrame - GeeksforGeeks
import pandas as pd df = ... ... Returns new DataFrames with updated column names. Use df.columns.str.replace() to replace unwanted characters in column names....
Published: October 3, 2025
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas replace substring in dataframe
Pandas Replace Substring in DataFrame - Spark By {Examples}
June 6, 2025 - You can find how to replace substrings in a pandas DataFrame column using the replace() method with lambda functions. This versatile method allows you to
🌐
Favtutor
favtutor.com › articles › rename-column-pandas
How to Rename a Column in Pandas (with code)
November 22, 2023 - Original DataFrame: name age 0 John 25 1 Jane 30 2 Jade 35 Modified DataFrame: user_name_info user_age_info 0 John 25 1 Jane 30 2 Jade 35 · Pandas provides the Dataframe.columns.str.replace method, which allows you to replace specific texts within column names.
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › python-pandas-series-str-replace-to-replace-text-in-a-series
Python | Pandas Series.str.replace() to replace text in a series - GeeksforGeeks
July 11, 2025 - After that only teams having team name "New Boston Celtics" are displayed using .where() method. ... # importing pandas module import pandas as pd # reading csv file from url data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv") # overwriting column with replaced value of age data["Team"]= data["Team"].str.replace("boston", "New Boston", case = False) # creating a filter for age column # where age = "Twenty five" filter = data["Team"]=="New Boston Celtics" # printing only filtered columns data.where(filter).dropna()
🌐
GeeksforGeeks
geeksforgeeks.org › python › pandas-rename-column
Pandas Rename Column - GeeksforGeeks
July 23, 2025 - This is useful when we want to apply transformations such as converting all column names to uppercase, applying string operations, or removing unwanted characters. Use list comprehension to modify the columns list. ... In this case, all column names are converted to uppercase. This method is highly customizable and allows us to apply conditions like removing spaces, changing the case, or applying regular expressions. If we need to replace specific characters or patterns in column names, we can use str.replace().