Skip to content

DOC: minor fix in extract docstring #5838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1057,14 +1057,14 @@ You can check whether elements contain a pattern:
.. ipython:: python

pattern = r'[a-z][0-9]'
Series(['1', '2', '3a', '3b', '03c']).contains(pattern)
Series(['1', '2', '3a', '3b', '03c']).str.contains(pattern)

or match a pattern:


.. ipython:: python

Series(['1', '2', '3a', '3b', '03c']).match(pattern, as_indexer=True)
Series(['1', '2', '3a', '3b', '03c']).str.match(pattern, as_indexer=True)

The distinction between ``match`` and ``contains`` is strictness: ``match``
relies on strict ``re.match``, while ``contains`` relies on ``re.search``.
Expand Down
19 changes: 14 additions & 5 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,11 @@ def str_match(arr, pat, case=True, flags=0, na=np.nan, as_indexer=False):

Returns
-------
boolean Series
Series of boolean values
if as_indexer=True
Series of tuples
if as_indexer=False, default but deprecated

Returns
-------
Series of boolean values

See Also
--------
contains : analagous, but less strict, relying on re.search instead of
Expand Down Expand Up @@ -414,14 +410,27 @@ def str_extract(arr, pat, flags=0):
A pattern with more than one group will return a DataFrame.

>>> Series(['a1', 'b2', 'c3']).str.extract('([ab])(\d)')
0 1
0 a 1
1 b 2
2 NaN NaN

A pattern may contain optional groups.

>>> Series(['a1', 'b2', 'c3']).str.extract('([ab])?(\d)')
0 1
0 a 1
1 b 2
2 NaN 3

Named groups will become column names in the result.

>>> Series(['a1', 'b2', 'c3']).str.extract('(?P<letter>[ab])(?P<digit>\d)')
letter digit
0 a 1
1 b 2
2 NaN NaN

"""
regex = re.compile(pat, flags=flags)

Expand Down