Skip to content

DOC: update the Series.str.ismethods docstring #20913

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
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
139 changes: 136 additions & 3 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import numpy as np

from pandas.compat import zip
Expand Down Expand Up @@ -2400,12 +2401,144 @@ def rindex(self, sub, start=0, end=None):
_shared_docs['swapcase'])

_shared_docs['ismethods'] = ("""
Check whether all characters in each string in the Series/Index
are %(type)s. Equivalent to :meth:`str.%(method)s`.
Check whether all characters in each string are %(type)s.

This is equivalent to running the Python string method
:meth:`str.%(method)s` for each element of the Series/Index. If a string
has zero characters, ``False`` is returned for that check.

Returns
-------
is : Series/array of boolean values
Series or Index of bool
Series or Index of boolean values with the same length as the original
Series/Index.

See Also
--------
Series.str.isalpha : Check whether all characters are alphabetic.
Series.str.isnumeric : Check whether all characters are numeric.
Series.str.isalnum : Check whether all characters are alphanumeric.
Series.str.isdigit : Check whether all characters are digits.
Series.str.isdecimal : Check whether all characters are decimal.
Series.str.isspace : Check whether all characters are whitespace.
Series.str.islower : Check whether all characters are lowercase.
Series.str.isupper : Check whether all characters are uppercase.
Series.str.istitle : Check whether all characters are titlecase.

Examples
--------
**Checks for Alphabetic and Numeric Characters**

>>> s1 = pd.Series(['one', 'one1', '1', ''])

>>> s1.str.isalpha()
0 True
1 False
2 False
3 False
dtype: bool

>>> s1.str.isnumeric()
0 False
1 False
2 True
3 False
dtype: bool

>>> s1.str.isalnum()
0 True
1 True
2 True
3 False
dtype: bool

Note that checks against characters mixed with any additional punctuation
or whitespace will evaluate to false for an alphanumeric check.

>>> s2 = pd.Series(['A B', '1.5', '3,000'])
>>> s2.str.isalnum()
0 False
1 False
2 False
dtype: bool

**More Detailed Checks for Numeric Characters**

There are several different but overlapping sets of numeric characters that
can be checked for.

>>> s3 = pd.Series(['23', '³', '⅕', ''])

The ``s3.str.isdecimal`` method checks for characters used to form numbers
in base 10.

>>> s3.str.isdecimal()
0 True
1 False
2 False
3 False
dtype: bool

The ``s.str.isdigit`` method is the same as ``s3.str.isdecimal`` but also
includes special digits, like superscripted and subscripted digits in
unicode.

>>> s3.str.isdigit()
0 True
1 True
2 False
3 False
dtype: bool

The ``s.str.isnumeric`` method is the same as ``s3.str.isdigit`` but also
includes other characters that can represent quantities such as unicode
fractions.

>>> s3.str.isnumeric()
0 True
1 True
2 True
3 False
dtype: bool

**Checks for Whitespace**

>>> s4 = pd.Series([' ', '\\t\\r\\n ', ''])
>>> s4.str.isspace()
0 True
1 True
2 False
dtype: bool

**Checks for Character Case**

>>> s5 = pd.Series(['leopard', 'Golden Eagle', 'SNAKE', ''])

>>> s5.str.islower()
0 True
1 False
2 False
3 False
dtype: bool

>>> s5.str.isupper()
0 False
1 False
2 True
3 False
dtype: bool

The ``s5.str.istitle`` method checks for whether all words are in title
case (whether only the first letter of each word is capitalized). Words are
assumed to be as any sequence of non-numeric characters seperated by
whitespace characters.

>>> s5.str.istitle()
0 False
1 True
2 False
3 False
dtype: bool
""")
_shared_docs['isalnum'] = dict(type='alphanumeric', method='isalnum')
_shared_docs['isalpha'] = dict(type='alphabetic', method='isalpha')
Expand Down