Apply uppercase to a column in Pandas dataframe

Analyzing a real world data is some what 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 uppercase each letter in any specific column in given dataframe. Let’s see how can we Apply uppercase to a column in Pandas dataframe.

Let’s create a dataframe using nba.csv.



filter_none

edit
close

play_arrow

link
brightness_4
code

# Import pandas package 
import pandas as pd 
    
# making data frame 
    
# calling head() method  
# storing in new variable 
data_top = data.head(10
    
# display 
data_top

chevron_right


Output:

There are certain methods we can change/modify the case of column in Pandas dataframe. Let’s see how can we apply uppercase to a column in Pandas dataframe using upper() method.

Method #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import pandas package 
import pandas as pd 
    
# making data frame 
      
# display 
data['Name'] = data['Name'].str.upper()
  
data.head()

chevron_right


Output:

 

Method #2: Using lambda with upper() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import pandas package 
import pandas as pd 
    
# making data frame 
  
  
# removing null values to avoid errors  
data.dropna(inplace = True)  
  
# Applying upper() method on 'College' column
data['College'].apply(lambda x: x.upper()).head(10)

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.