How to lowercase column names in Pandas dataframe

Analyzing real-world data is somewhat difficult because we need to take various things into consideration. Apart from getting the useful data from large datasets, keeping data in required format is also very important.

One might encounter a situation where we need to lowercase each letter in any specific column in given dataframe. Let’s see how to lowercase column names in Pandas dataframe.

Let’s create a dataframe from the dict of lists.



filter_none

edit
close

play_arrow

link
brightness_4
code

# Create a simple dataframe
   
# importing pandas as pd
import pandas as pd
  
# creating a dataframe
df = pd.DataFrame({'A': ['John', 'bODAY', 'MinA', 'Peter', 'nicky'],
                  'B': ['masters', 'graduate', 'graduate',
                                   'Masters', 'Graduate'],
                  'C': [27, 23, 21, 23, 24]})
   
df

chevron_right


Output:

There are certain methods we can change/modify the case of column in pandas dataframe. Let’s see how can we lowercase column names in Pandas dataframe using lower() method.

Method #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Create a simple dataframe
   
# importing pandas as pd
import pandas as pd
  
   
# creating a dataframe
df = pd.DataFrame({'A': ['John', 'bODAY', 'MinA', 'Peter', 'nicky'],
                  'B': ['masters', 'graduate', 'graduate'
                                   'Masters', 'Graduate'],
                  'C': [27, 23, 21, 23, 24]})
   
df['A'] = df['A'].str.lower()
  
df

chevron_right


Output:

 
Method #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Create a simple dataframe
   
# importing pandas as pd
import pandas as pd
  
   
# creating a dataframe
df = pd.DataFrame({'A': ['John', 'bODAY', 'MinA', 'Peter', 'nicky'],
                  'B': ['masters', 'graduate', 'graduate',
                                   'Masters', 'Graduate'],
                  'C': [27, 23, 21, 23, 24]})
   
df['A'].apply(lambda x: x.lower())

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.