@@ -196,9 +196,9 @@ DataFrame with one column per group.
196196 Elements that do not match return a row filled with ``NaN ``. Thus, a
197197Series of messy strings can be "converted" into a like-indexed Series
198198or DataFrame of cleaned-up or more useful strings, without
199- necessitating ``get() `` to access tuples or ``re.match `` objects. The
200- results dtype always is object, even if no match is found and the
201- result only contains ``NaN ``.
199+ necessitating ``get() `` to access tuples or ``re.match `` objects. The
200+ dtype of the result is always object, even if no match is found and
201+ the result only contains ``NaN ``.
202202
203203Named groups like
204204
@@ -275,15 +275,16 @@ Extract all matches in each subject (extractall)
275275
276276.. _text.extractall :
277277
278+ .. versionadded :: 0.18.0
279+
278280Unlike ``extract `` (which returns only the first match),
279281
280282.. ipython :: python
281283
282284 s = pd.Series([" a1a2" , " b1" , " c1" ], [" A" , " B" , " C" ])
283285 s
284- s.str.extract(" [ab](?P<digit>\d)" , expand = False )
285-
286- .. versionadded :: 0.18.0
286+ two_groups = ' (?P<letter>[a-z])(?P<digit>[0-9])'
287+ s.str.extract(two_groups, expand = True )
287288
288289 the ``extractall `` method returns every match. The result of
289290``extractall `` is always a ``DataFrame `` with a ``MultiIndex `` on its
@@ -292,30 +293,29 @@ indicates the order in the subject.
292293
293294.. ipython :: python
294295
295- s.str.extractall(" [ab](?P<digit>\d) " )
296+ s.str.extractall(two_groups )
296297
297298 When each subject string in the Series has exactly one match,
298299
299300.. ipython :: python
300301
301302 s = pd.Series([' a3' , ' b3' , ' c2' ])
302303 s
303- two_groups = ' (?P<letter>[a-z])(?P<digit>[0-9])'
304304
305305 then ``extractall(pat).xs(0, level='match') `` gives the same result as
306306``extract(pat) ``.
307307
308308.. ipython :: python
309309
310- extract_result = s.str.extract(two_groups, expand = False )
310+ extract_result = s.str.extract(two_groups, expand = True )
311311 extract_result
312312 extractall_result = s.str.extractall(two_groups)
313313 extractall_result
314314 extractall_result.xs(0 , level = " match" )
315315
316316
317317 Testing for Strings that Match or Contain a Pattern
318- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
318+ ---------------------------------------------------
319319
320320You can check whether elements contain a pattern:
321321
@@ -355,7 +355,7 @@ Methods like ``match``, ``contains``, ``startswith``, and ``endswith`` take
355355 s4.str.contains(' A' , na = False )
356356
357357 Creating Indicator Variables
358- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
358+ ----------------------------
359359
360360You can extract dummy variables from string columns.
361361For example if they are separated by a ``'|' ``:
0 commit comments