pandas replace substring in column names 1

pandas replace substring in column names

df.columns = df.columns.astype(str).str.replace("[()]", "_")

Here is what the above code is Doing:
1. We’re using the .str accessor to access the string methods on the column names.
2. We’re using the .replace() method to replace the characters in the column names.
3. We’re using the .astype() method to change the column names to strings.

Similar Posts