Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data preprocessing
  • Data Manipulation
  • Data Analysis using Pandas
  • EDA
  • Pandas Exercise
  • Pandas AI
  • Numpy
  • Matplotlib
  • Plotly
  • Data Analysis
  • Machine Learning
  • Data science
Open In App
Next Article:
How to Manipulate Strings in Pandas?
Next article icon

How to Manipulate Strings in Pandas?

Last Updated : 05 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Pandas Library provides multiple methods that can be used to manipulate string according to the required output. But first, let's create a Pandas dataframe.

Python3
import pandas as pd  data = [[1, "ABC KUMAR", "xYZ"], [2, "BCD", "XXY"],         [3, "CDE KUMAR", "ZXX"], [3, "DEF", "xYZZ"]]  cfile = pd.DataFrame(data, columns = ["SN", "FirstName", "LastName"])  cfile 

Output:

"Pandas" library provides a ".str()"  method that can be used to create any data of the data frame into a string,  After that any string operation defined in python documentation or in this article can be used on that data.

Below is  the code that illustrates some examples

Python3
# find firstname starting with 'D' result = cfile.FirstName.str.startswith('D') print(result)  # find lasttname containing 'XX' result = cfile.LastName.str.contains('XX') print(result)   # split FirstName on the basis of ' ' result = cfile.FirstName.str.split() print(result)   # find length of lasttname result = cfile.LastName.str.len() print(result)  # Capitalize the first Letter of LastName result = cfile.LastName.str.capitalize() print(result)  # Capitalize all Letter of LastName result = cfile.LastName.str.upper() print(result)  # Convert all Letter of LastName to lowercase result = cfile.LastName.str.lower() print(result) 

Output:

0    False  1    False  2    False  3     True  Name: FirstName, dtype: bool  0    False  1     True  2     True  3    False  Name: LastName, dtype: bool  0    [ABC, KUMAR]  1           [BCD]  2    [CDE, KUMAR]  3           [DEF]  Name: FirstName, dtype: object  0    3  1    3  2    3  3    4  Name: LastName, dtype: int64  0     Xyz  1     Xxy  2     Zxx  3    Xyzz  Name: LastName, dtype: object  0     XYZ  1     XXY  2     ZXX  3    XYZZ  Name: LastName, dtype: object  0     xyz  1     xxy  2     zxx  3    xyzz  Name: LastName, dtype: object

Next Article
How to Manipulate Strings in Pandas?

I

iamjpsonkar
Improve
Article Tags :
  • Python
  • Python-pandas
  • Python pandas-dataFrame
  • Python Pandas-exercise
Practice Tags :
  • python

Similar Reads

    String manipulations in Pandas DataFrame
    String manipulation is the process of changing, parsing, splicing, pasting or analyzing strings. As we know that sometimes data in the string is not suitable for manipulating the analysis or get a description of the data. But Python is known for its ability to manipulate strings. In this article we
    4 min read
    Top 10 String methods in Pandas
    In simple terms, string methods in Pandas are a set of tools that help us manipulate and work with text (also known as strings) in our data. Pandas, which is a powerful Python library for data manipulation, provides a variety of built-in tools to make that job easier. Instead of manually going throu
    3 min read
    How to remove numbers from string in Python - Pandas?
    In this article, let's see how to remove numbers from string in Pandas. Currently, we will be using only the .csv file for demonstration purposes, but the process is the same for other types of files. The function read_csv() is used to read CSV files. Syntax:  for the method 'replace()': str.replace
    2 min read
    How to lowercase strings in a column in Pandas dataframe
    Analyzing real-world data is somewhat 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 lowercase each letter in any spe
    2 min read
    How to Convert Integers to Strings in Pandas DataFrame?
    In this article, we'll look at different methods to convert an integer into a string in a Pandas dataframe. In Pandas, there are different functions that we can use to achieve this task : map(str)astype(str)apply(str)applymap(str) Example 1 : In this example, we'll convert each value of a column of
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences