Function to clean column names

In case it’s useful :

Use the following criteria to update the column names:

Make all the capitalization lowercase.
Remove any trailing whitespace from the end of the strings.
Replace spaces with underscores (’_’).

import re
def clean_col_names( df, ) :
    """ df edited in place (no return value) """
    # convert to lowercase, remove leading/trailing whitespace, replace space with _
    mapper_dict = {col : col.lower().strip().replace(' ', '_') for col in df.columns }
    df.rename( mapper_dict, inplace=True, axis=1 )

Could be an issue with the site - when I tried posting this, I kept getting 500 Internal Server Err…

I had to first post just the “In case it’s useful” and then edit it…

Could be the site was down for a while @Sahil?


The site was not down but I can definitely see an error for this topic in our community logs. I will get it explored by our engineers during our upcoming community maintenance.