pandas.Series.str.isnumeric#
- Series.str.isnumeric()[source]#
Check whether all characters in each string are numeric.
This is equivalent to running the Python string method
str.isnumeric()for each element of the Series/Index. If a string has zero characters,Falseis returned for that check.- Returns:
- Series or Index of bool
Series or Index of boolean values with the same length as the original Series/Index.
See also
Series.str.isalphaCheck whether all characters are alphabetic.
Series.str.isalnumCheck whether all characters are alphanumeric.
Series.str.isdigitCheck whether all characters are digits.
Series.str.isdecimalCheck whether all characters are decimal.
Series.str.isspaceCheck whether all characters are whitespace.
Series.str.islowerCheck whether all characters are lowercase.
Series.str.isasciiCheck whether all characters are ascii.
Series.str.isupperCheck whether all characters are uppercase.
Series.str.istitleCheck whether all characters are titlecase.
Examples
The
s.str.isnumericmethod is the same ass3.str.isdigitbut also includes other characters that can represent quantities such as unicode fractions.>>> s1 = pd.Series(['one', 'one1', '1', '', '³', '⅕']) >>> s1.str.isnumeric() 0 False 1 False 2 True 3 False 4 True 5 True dtype: bool
For a string to be considered numeric, all its characters must have a Unicode numeric property matching
str.is_numeric(). As a consequence, the following cases are not recognized as numeric:Decimal numbers (e.g., “1.1”): due to period
"."Negative numbers (e.g., “-5”): due to minus sign
"-"Scientific notation (e.g., “1e3”): due to characters like
"e"
>>> s2 = pd.Series(["1.1", "-5", "1e3"]) >>> s2.str.isnumeric() 0 False 1 False 2 False dtype: bool