pandas working with text data

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值