What about other string methods?

QuestionsQuestions8 SkillsProPandas Textual DataAug, 06 2025
0237

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:

  1. Uppercase: Convert strings to uppercase.

    df['Name'] = df['Name'].str.upper()
  2. Title Case: Convert strings to title case (first letter of each word capitalized).

    df['Name'] = df['Name'].str.title()
  3. Strip: Remove leading and trailing whitespace.

    df['Name'] = df['Name'].str.strip()
  4. Replace: Replace occurrences of a substring with another substring.

    df['Name'] = df['Name'].str.replace('Alice', 'Alicia')
  5. Contains: Check if a substring is present in the string.

    df['Contains_A'] = df['Name'].str.contains('A')
  6. Split: Split strings into lists based on a delimiter.

    df['Education_Split'] = df['Education'].str.split()
  7. Length: Get the length of each string.

    df['Name_Length'] = df['Name'].str.len()
  8. 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.

0 Comments

no data
Be the first to share your comment!