Pandas: Refer to column name, case insensitive Pandas: Refer to column name, case insensitive python python

Pandas: Refer to column name, case insensitive


you can just call str.lower on the columns:

In [12]:df = pd.DataFrame(columns=['Size','COLOUR','caTegory'])df.columnsOut[12]:Index(['Size', 'COLOUR', 'caTegory'], dtype='object')In [14]:df.columns = df.columns.str.lower()df.columnsOut[14]:Index(['size', 'colour', 'category'], dtype='object')


Have you tried changing the column names using df.columns to all lower or upper case? You can do that using

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

Maybe that can solve your issue.


Why not normalize the column names in df?

df.columns = [c.lower() for c in df.columns]