A string is an immutable sequence of Unicode characters. In pandas, string values become especially useful when a Series exposes the str accessor, which applies string methods element by element and returns a new Series. section 9.0
Common Series operations turn textual data into searchable, measurable, and normalized values:
- Measure values with str.len(), select digit-only values with str.isdigit(), and search with str.contains(). section 9.0
- Normalize text with str.lower() and str.strip(), then count results with value_counts(). section 9.2
- Chain transformations, assign returned Series to new columns, or apply custom functions with Series.apply(). section 9.0 section 9.2
Cleaning and counting words
Read a small text file, split it into words, and create a Series. Normalize capitalization and punctuation before counting: s.str.lower().str.strip(string.punctuation).value_counts().head(10). The same Series can identify capitalized words with a regular expression or calculate average vowel counts with a custom function. section 9.2
Table 9.1 What you need to know (view table figure)
Use the method table to compare string operations by returned object, purpose, and example syntax. section 9.0
Pandas historically stored Python strings with object dtype, which could accidentally mix strings with other Python objects. StringDtype provides a text-specific alternative, paired with pd.NA for missing values. section 9.0























