← Back to Pandas Course | Chapter 5: Data Cleaning | Lesson 5 of 7

strip/replace/split का उपयोग

तीन everyday cleaning tools: whitespace trim करना, text swap करना, और strings को pieces में तोड़ना।

In this page:

  1. strip/replace/split
Syntax
python
df["column"].str.strip()
df["column"].str.replace("old", "new")
df["column"].str.split(separator)

strip/replace/split

str.strip surrounding whitespace remove करता है, str.replace text swap करता है (patterns के लिए regex=True के साथ), और str.split strings को lists में तोड़ता है। split में expand=True add करना pieces को separate columns में फैलाता है।

Note: plain text के लिए replace में regex=False set करें special characters के साथ surprises avoid करने के लिए।

उदाहरण: strip/replace/split

python
import pandas as pd

df = pd.DataFrame({"full": [" Ada Lovelace ", "Alan Turing"], "phone": ["555-1234", "555-9876"]})
df[["first", "last"]] = df["full"].str.strip().str.split(" ", expand=True)
df["phone"] = df["phone"].str.replace("-", "", regex=False)
print(df)

# Output:
#              full    phone first      last
# 0   Ada Lovelace   5551234   Ada  Lovelace
# 1     Alan Turing  5559876  Alan    Turing
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. expand=True भूल जाना और lists पाना
  2. regex on होने पर . को plain text treat करना
  3. cleaned result वापस assign न करना
चैप्टर सारांश
  • strip whitespace trim करता है
  • replace text swap करता है
  • split strings तोड़ता है
  • expand=True columns देता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.