pandas working with text data
2015-07-23 07:21
363 查看
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.
相关文章推荐
- programming-challenges Polynomial coefficients (110506) 题解
- 创业者两大特征:喜欢折腾与坚持不懈
- pandas essential functions
- Leetcode NO.111 Minimum Depth of Binary Tree
- Java 中最常见的 5 个错误
- 滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(持续更新...)
- 7.23翻倍奖励——滴滴快车单(成交率≥80%,≥10指派单)
- 2015年07月21日第13天笔记
- 7.23翻倍奖励——滴滴快车单(成交率≥60%,≥5指派单)
- 后台系统重构碰到的问题
- 7.23翻倍奖励——滴滴快车单(成交率≥50%,≥1指派单)
- C Objcet类
- programming-challenges A multiplication game (110505) 题解
- Git 使用中的问题
- Scala中隐式转换内幕操作规则揭秘
- 多线程(线程的概述,创建线程,控制线程,线程同步,线程池)
- 如何打印运行时加载类的包名(物理包名,不是路径)
- 优步司机如何联系客服?uber客服渠道,Uber优步司机客服渠道
- LeetCode Happy Number
- LeetCode Happy Number