Keeping text in right format is always important. The data coming out of Python eventually helps in presenting the insights. In case the texts are not in proper format, it will require additional cleaning in later stages. Fields can be present as mixed case in the text. The objective is to create a column with all letters as upper case, to achieve this Python has upper function. Python string function str.upper() helps in creating Upper case texts in Python. In this article we will learn how to do uppercase in Python with the help of an example.
Emma has customer data available with her for her company. She has Gender field available. The field is in Proper case. She wants to create all Uppercase field from the same. For example, for “Male” new Gender column should look like “MALE”
Python Capitalize All Letters
- Step 1: Import all the necessary modules.
import pandas as pd
- Step 2: Use str.upper function to convert text to upper case. To use this function, pass the column name along with Dataframe in the beginning which helps to identify column for upcase. Here is the syntax to upcase ‘Gender’ column.
Customer_Data['Gender_Updated'] = Customer_Data['Gender'].str.upper()
- Step 3: Check the output data quality to assess the observations in final Dataframe.
Customer_Data.head(15)
Thus, Emma is able to create column in Dataframe as per her requirement in Python.
To get top certifications in Python and build your resume visit here. Also, you can read books listed here to build strong knowledge around Python.
Visit us below for video tutorial:
📬 Stay Ahead in Data Science & AI – Subscribe to Newsletter!
- 🎯 Interview Series: Curated questions and answers for freshers and experienced candidates.
- 📊 Data Science for All: Simplified articles on key concepts, accessible to all levels.
- 🤖 Generative AI for All: Easy explanations on Generative AI trends transforming industries.
💡 Why Subscribe? Gain expert insights, stay ahead of trends, and prepare with confidence for your next interview.
👉 Subscribe here: