Skip to content

Commit f7bdd34

Browse files
Merge pull request #5838 from danielballan/extract-docstring
DOC: minor fix in extract docstring
2 parents 3881f03 + 33b18af commit f7bdd34

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

doc/source/basics.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1057,14 +1057,14 @@ You can check whether elements contain a pattern:
10571057
.. ipython:: python
10581058
10591059
pattern = r'[a-z][0-9]'
1060-
Series(['1', '2', '3a', '3b', '03c']).contains(pattern)
1060+
Series(['1', '2', '3a', '3b', '03c']).str.contains(pattern)
10611061
10621062
or match a pattern:
10631063

10641064

10651065
.. ipython:: python
10661066
1067-
Series(['1', '2', '3a', '3b', '03c']).match(pattern, as_indexer=True)
1067+
Series(['1', '2', '3a', '3b', '03c']).str.match(pattern, as_indexer=True)
10681068
10691069
The distinction between ``match`` and ``contains`` is strictness: ``match``
10701070
relies on strict ``re.match``, while ``contains`` relies on ``re.search``.

pandas/core/strings.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,11 @@ def str_match(arr, pat, case=True, flags=0, na=np.nan, as_indexer=False):
333333
334334
Returns
335335
-------
336-
boolean Series
336+
Series of boolean values
337337
if as_indexer=True
338338
Series of tuples
339339
if as_indexer=False, default but deprecated
340340
341-
Returns
342-
-------
343-
Series of boolean values
344-
345341
See Also
346342
--------
347343
contains : analagous, but less strict, relying on re.search instead of
@@ -414,14 +410,27 @@ def str_extract(arr, pat, flags=0):
414410
A pattern with more than one group will return a DataFrame.
415411
416412
>>> Series(['a1', 'b2', 'c3']).str.extract('([ab])(\d)')
413+
0 1
414+
0 a 1
415+
1 b 2
416+
2 NaN NaN
417417
418418
A pattern may contain optional groups.
419419
420420
>>> Series(['a1', 'b2', 'c3']).str.extract('([ab])?(\d)')
421+
0 1
422+
0 a 1
423+
1 b 2
424+
2 NaN 3
421425
422426
Named groups will become column names in the result.
423427
424428
>>> Series(['a1', 'b2', 'c3']).str.extract('(?P<letter>[ab])(?P<digit>\d)')
429+
letter digit
430+
0 a 1
431+
1 b 2
432+
2 NaN NaN
433+
425434
"""
426435
regex = re.compile(pat, flags=flags)
427436

0 commit comments

Comments
 (0)