Mastering Python String Methods for Data Analysis

🚀 Today I Learned: STRING METHODS in Python Learning Python is all about mastering the small details that make a big difference. Today, I explored string methods — and they’re incredibly powerful for cleaning, transforming, and analyzing text data. Here are some highlights from my practice session 👇 text1 = " hello python learners " # Remove spaces print(text1.strip()) # hello python learners # Convert cases print(text1.upper().strip()) # HELLO PYTHON LEARNERS print(text1.title().strip()) # Hello Python Learners print(text1.lower().strip()) # hello python learners # Replace words print(text1.replace("python", "SQL").strip()) # hello SQL learners # Count occurrences print(text1.count("o")) # 3 # Check start of string print(text1.strip().startswith("hello")) # True # Split & Join words = text1.strip().split() print(words) # ['hello', 'python', 'learners'] print("-".join(words)) # hello-python-learners # Numeric check mobile = "8800182677" print(mobile.isnumeric()) # True # Find position msg = "Welcome to Python Course" print(msg.find("P")) # 11 # Extract domain email = "student@example.com" domain = email[email.find("@")+1:] print(domain) # example.com # Clean price text price_text = "Price: ₹3500/-" clean_price = (price_text.replace("Price:", "") .replace("₹", "") .replace("/-", "") .strip()) print(clean_price) # 3500 🔑 Key Takeaways - strip(), split(), and join() are lifesavers for text cleaning. - Case conversions (upper, lower, title) make formatting consistent. - replace(), count(), and find() help in quick text manipulation. - Real‑world use cases: cleaning messy data, extracting domains, validating numeric strings, and preparing text for reports.

To view or add a comment, sign in

Explore content categories