pythonpandasanalytics

How do I lowercase columns names and removing white spaces?


I need to lowercase the column names and and get rid of the gaps. After using the method .lower() I got an error:

'Index' object has no attribute 'lower'

enter image description here

What am I doing incorrectly?


Solution

  • Lower casing column names:

    df.columns = df.columns.str.lower()
    

    Deleting white spaces:

    df.columns = df.columns.str.strip()