Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
python

How to use the lower() function in pandas

Maria Elijah

The lower() function

The pandas lower() function is used to convert all characters in a string to lowercase.

Syntax

dataframe["columnname"][index].lower()

Note: You cannot apply the lower() function on the entire column of a DataFrame.

Example

The following code shows how to use the lower() function:

import pandas as pd

# Create a DataFrame
df = pd.DataFrame({
    "name": ["Maria","Paul","Eva","Oliver","Sebastian","Camila"],
    "age":[20,22,32,26,29,30],
    "salary":[2000,2500,4000,3500,4200,3000],
    "gender":["female","male","female","male","male"
    ,"female"]
})

# Convert string to lowercase using lower()
print(df["name"][4].lower())
Convert string to lowercase

Explanation

In the code above:

  • Line 1: We import the pandas library.

  • Lines 4–10: We create a DataFrame, df, from a dictionary.

  • Line 13: We use the lower() function to convert the name at index 44 in the name column to lowercase.

RELATED TAGS

pandas
python
RELATED COURSES

View all Courses

Keep Exploring