String Operations
Python provides extensive string operations for text processing.
String Methods
Lower, upper, title case: s.lower(), s.upper(), s.title(). Strip whitespace: s.strip(). Replace: s.replace('old', 'new').
Split: s.split(',') breaks into list. Join: ', '.join(list) combines list.
Regular Expressions
re module handles regex. re.findall(pattern, string) finds all matches. re.sub(pattern, repl, string) replaces.
Pattern: r'\d+' matches digits. r'\w+' matches word characters. Anchors: ^, $ match string boundaries.
Pandas String Methods
Series.str provides vectorized string operations. str.lower(), str.strip(), str.replace() work on entire Series.
str.contains(), str.startswith() for filtering. str.extract() captures groups.
Key Takeaways
- String methods handle basic text cleaning
- Regular expressions enable complex pattern matching
- Pandas provides vectorized string operations