In [13]: dollars = Series([’12’, ’-$10’, ’$10,000’])
# This does what you’d naively expect:
In [14]: dollars.str.replace(’$’, ’’)
Out[14]:
0 12
1 -10
2 10,000
dtype: object
In [22]: Series([’a1’, ’b2’, ’c3’]).str.extract(’(?P<letter>[ab])(?P<digit>\d)’)
Out[22]:
letter digit
0 a 1
1 b 2
2 NaN NaN
and optional groups like
In [23]: Series([’a1’, ’b2’, ’3’]).str.extract(’(?P<letter>[ab])?(?P<digit>\d)’)
Out[23]:
letter digit
0 a 1
1 b 2
2 NaN 3
Method Summary
Method Description
cat(): Concatenate strings
split(): Split strings on delimiter
get(): Index into each element (retrieve i-th element)
join(): Join strings in each element of the Series with passed separator
contains(): Return boolean array if each string contains pattern/regex
replace(): Replace occurrences of pattern/regex with some other string
repeat(): Duplicate values (s.str.repeat(3) equivalent to x * 3)
pad(): Add whitespace to left, right, or both sides of strings
center(): Equivalent to pad(side=’both’)
wrap(): Split long strings into lines with length less than a given width
slice(): Slice each string in the Series
slice_replace():Replace slice in each string with passed value
count(): Count occurrences of pattern
startswith(): Equivalent to str.startswith(pat) for each element
endswith(): Equivalent to str.endswith(pat) for each element
findall(): Compute list of all occurrences of pattern/regex for each string
match(): Call re.match on each element, returning matched groups as list
extract(): Call re.match on each element, as match does, but return matched groups as strings for
convenience.
len(): Compute string lengths
strip(): Equivalent to str.strip
rstrip(): Equivalent to str.rstrip
lstrip(): Equivalent to str.lstrip
lower(): Equivalent to str.lower
upper(): Equivalent to str.upper
10.4.