Skip to content

Commit b12b7ae

Browse files
arjunsharma97jreback
authored andcommitted
DOC: Improved the docstring of str.extract() (Delhi) (pandas-dev#20141)
1 parent e84cf2a commit b12b7ae

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pandas/core/strings.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -840,19 +840,22 @@ def _str_extract_frame(arr, pat, flags=0):
840840

841841
def str_extract(arr, pat, flags=0, expand=True):
842842
r"""
843+
Extract capture groups in the regex `pat` as columns in a DataFrame.
844+
843845
For each subject string in the Series, extract groups from the
844-
first match of regular expression pat.
846+
first match of regular expression `pat`.
845847
846848
Parameters
847849
----------
848850
pat : string
849-
Regular expression pattern with capturing groups
851+
Regular expression pattern with capturing groups.
850852
flags : int, default 0 (no flags)
851-
re module flags, e.g. re.IGNORECASE
852-
853+
``re`` module flags, e.g. ``re.IGNORECASE``.
854+
See :mod:`re`
853855
expand : bool, default True
854-
* If True, return DataFrame.
855-
* If False, return Series/Index/DataFrame.
856+
If True, return DataFrame with one column per capture group.
857+
If False, return a Series/Index if there is one capture group
858+
or DataFrame if there are multiple capture groups.
856859
857860
.. versionadded:: 0.18.0
858861
@@ -875,7 +878,7 @@ def str_extract(arr, pat, flags=0, expand=True):
875878
A pattern with two groups will return a DataFrame with two columns.
876879
Non-matches will be NaN.
877880
878-
>>> s = Series(['a1', 'b2', 'c3'])
881+
>>> s = pd.Series(['a1', 'b2', 'c3'])
879882
>>> s.str.extract(r'([ab])(\d)')
880883
0 1
881884
0 a 1
@@ -914,7 +917,6 @@ def str_extract(arr, pat, flags=0, expand=True):
914917
1 2
915918
2 NaN
916919
dtype: object
917-
918920
"""
919921
if not isinstance(expand, bool):
920922
raise ValueError("expand must be True or False")

0 commit comments

Comments
 (0)