矢量化的字符串方法

Series is equipped with a set of string processing methods that make it easy to operate on each element of the array. Perhaps most importantly, these methods exclude missing/NA values automatically. These are accessed via the Series’s str attribute and generally have names matching the equivalent (scalar) built-in string methods. For example:

  1. In [305]: s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
  2. In [306]: s.str.lower()
  3. Out[306]:
  4. 0 a
  5. 1 b
  6. 2 c
  7. 3 aaba
  8. 4 baca
  9. 5 NaN
  10. 6 caba
  11. 7 dog
  12. 8 cat
  13. dtype: object

Powerful pattern-matching methods are provided as well, but note that pattern-matching generally uses regular expressions by default (and in some cases always uses them).

Please see Vectorized String Methods for a complete description.