Home > Mobile >  renaming pandas dataframe column containing special characters
renaming pandas dataframe column containing special characters

Time:12-31

I have a pandas dataframe containing a few hundred columns. Many of these columns end in "($)" [quotation marks are not shown in actual code].

I used the following but was not able to then apply to my columns

# Remove ($)
for i in WholeLoan_df.columns:
    re.sub("[($)]","",i)

Any help is appreciated.

Thank you,

CodePudding user response:

Rather than use a loop, use rstrip:

df.columns = df.columns.str.rstrip(r' ($)'
  • Related