5分钟
字符串操作
1. 通过Series.map()方法,所有字符串和正则表达式方法都能应用于各个值。但是如果存在NaN就会报错。为了解决这个问题,pandas提供了一些能够跳过NaN值的字符串操作方法。
2. Series.str能够将Series的值当作字符串处理,并且你可以通过Series.str.func来应用某些函数。其中func可以为:
Series.str.capitalize()Series.str.cat([others, sep, na_rep])Series.str.center(width[, fillchar])Series.str.contains(pat[, case=True, flags=0, na=nan, regex=True])Series.str.count(pat[, flags])Series.str.decode(encoding[, errors])Series.str.encode(encoding[, errors])Series.str.endswith(pat[, na])Series.str.extract(pat[, flags, expand])Series.str.extractall(pat[, flags])Series.str.find(sub[, start, end])Series.str.findall(pat[, flags])Series.str.get(i)Series.str.index(sub[, start, end])Series.str.join(sep)Series.str.len()Series.str.ljust(width[, fillchar])Series.str.lower()Series.str.lstrip([to_strip])Series.str.match(pat[, case=True, flags=0, na=nan, as_indexer=False])Series.str.normalize(form)Series.str.pad(width[, side, fillchar])Series.str.partition([pat, expand])Series.str.repeat(repeats)Series.str.replace(pat, repl[, n, case, flags])Series.str.rfind(sub[, start, end])Series.str.rindex(sub[, start, end])Series.str.rjust(width[, fillchar])Series.str.rpartition([pat, expand])Series.str.rstrip([to_strip])Series.str.slice([start, stop, step])Series.str.slice_replace([start, stop, repl])Series.str.split([pat, n, expand])Series.str.rsplit([pat, n, expand])Series.str.startswith(pat[, na])Series.str.strip([to_strip])Series.str.swapcase()Series.str.title()Series.str.translate(table[, deletechars])Series.str.upper()Series.str.wrap(width, **kwargs)Series.str.zfill(width)Series.str.isalnum()Series.str.isalpha()Series.str.isdigit()Series.str.isspace()Series.str.islower()Series.str.isupper()Series.str.istitle()Series.str.isnumeric()Series.str.isdecimal()Series.str.get_dummies([sep])
3. 你也可以通过Series.str[:3]这种索引操作来进行子串截取。或者使用Series.str.get()方法进行截取。
学员评价