In addition to converting strings to lowercase, there are several other string methods you can use in pandas to manipulate string data in DataFrames. Here are some common string methods:
-
Uppercase: Convert strings to uppercase.
df['Name'] = df['Name'].str.upper() -
Title Case: Convert strings to title case (first letter of each word capitalized).
df['Name'] = df['Name'].str.title() -
Strip: Remove leading and trailing whitespace.
df['Name'] = df['Name'].str.strip() -
Replace: Replace occurrences of a substring with another substring.
df['Name'] = df['Name'].str.replace('Alice', 'Alicia') -
Contains: Check if a substring is present in the string.
df['Contains_A'] = df['Name'].str.contains('A') -
Split: Split strings into lists based on a delimiter.
df['Education_Split'] = df['Education'].str.split() -
Length: Get the length of each string.
df['Name_Length'] = df['Name'].str.len() -
Join: Join elements of a list into a single string.
df['Joined'] = df['Education_Split'].str.join(', ')
These methods can be applied to individual columns or multiple columns using the apply() function as shown in the previous example.
