strip/replace/split का उपयोग
तीन everyday cleaning tools: whitespace trim करना, text swap करना, और strings को pieces में तोड़ना।
In this page:
Syntax
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
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. #}
आम गलतियां
- expand=True भूल जाना और lists पाना
- regex on होने पर . को plain text treat करना
- 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: