pandas.Series.str.isdecimal #
- 系列.str。isdecimal ( ) [来源] #
检查每个字符串中的所有字符是否都是十进制。
这相当于
str.isdecimal()
对 Series/Index 的每个元素运行 Python 字符串方法。如果字符串有零个字符,则False
返回该检查。- 返回:
- bool 的系列或索引
布尔值的系列或索引,其长度与原始系列/索引相同。
也可以看看
Series.str.isalpha
检查所有字符是否都是字母。
Series.str.isnumeric
检查所有字符是否都是数字。
Series.str.isalnum
检查所有字符是否都是字母数字。
Series.str.isdigit
检查所有字符是否都是数字。
Series.str.isdecimal
检查所有字符是否都是十进制。
Series.str.isspace
检查所有字符是否都是空格。
Series.str.islower
检查所有字符是否都是小写。
Series.str.isupper
检查所有字符是否都是大写。
Series.str.istitle
检查所有字符是否都是首字母大写。
例子
检查字母和数字字符
>>> 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
请注意,对于字母数字检查,对与任何其他标点符号或空格混合的字符进行检查将评估为 false。
>>> s2 = pd.Series(['A B', '1.5', '3,000']) >>> s2.str.isalnum() 0 False 1 False 2 False dtype: bool
对数字字符进行更详细的检查
可以检查多个不同但重叠的数字字符集。
>>> s3 = pd.Series(['23', '³', '⅕', ''])
该
s3.str.isdecimal
方法检查用于形成以 10 为基数的数字的字符。>>> s3.str.isdecimal() 0 True 1 False 2 False 3 False dtype: bool
该
s.str.isdigit
方法与 unicode 中的上标和下标数字相同s3.str.isdecimal
,但还包括特殊数字。>>> s3.str.isdigit() 0 True 1 True 2 False 3 False dtype: bool
该方法与其他可以表示数量的字符(例如 unicode 分数)
s.str.isnumeric
相同,但还包括其他字符。s3.str.isdigit
>>> s3.str.isnumeric() 0 True 1 True 2 True 3 False dtype: bool
检查空白
>>> s4 = pd.Series([' ', '\t\r\n ', '']) >>> s4.str.isspace() 0 True 1 True 2 False dtype: bool
检查字符大小写
>>> 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
该
s5.str.istitle
方法检查是否所有单词都采用标题大小写(是否仅每个单词的第一个字母大写)。假定单词是由空格字符分隔的任何非数字字符序列。>>> s5.str.istitle() 0 False 1 True 2 False 3 False dtype: bool