Home:ALL Converter>Replacing multiple special characters on dataframe

Replacing multiple special characters on dataframe

Ask Time:2022-07-01T21:25:35         Author:Deepak

Json Formatter

I have dataframe with 80+ columns and column names has special characters like colon, Ampersand, Slash, Minus, space and Parenthesis.

Currently, I'm doing multiple replace on df.columns, my code as follows:

df.columns = df.columns.str.replace(' ','').str.replace('-','').str.replace('&','').str.replace('/','').str.replace(':','').str.replace('(','').str.replace(')','')

Is there any betters ways to replace all special characters at once on dataframe column names.

Author:Deepak,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72829995/replacing-multiple-special-characters-on-dataframe
yy