mars.dataframe.Series.str.isalpha#

Series.str.isalpha()#

检查每个字符串中的所有字符是否都是字母。

这相当于对Series/Index的每个元素运行Python字符串方法 str.isalpha()。如果一个字符串 包含零个字符,则该检查返回False

Returns

与原始 Series/Index 长度相同的布尔值的系列或索引。

Return type

系列索引布尔值

另请参阅

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

检查所有字符是否为标题格式。

示例

检查字母和数字字符

>>> import mars.dataframe as md
>>> s1 = md.Series(['one', 'one1', '1', ''])
>>> s1.str.isalpha().execute()
0     True
1    False
2    False
3    False
dtype: bool
>>> s1.str.isnumeric().execute()
0    False
1    False
2     True
3    False
dtype: bool
>>> s1.str.isalnum().execute()
0     True
1     True
2     True
3    False
dtype: bool

请注意,混合任何额外标点符号或空白字符的字符在进行字母数字检查时将评估为假。

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

对数字字符进行更详细的检查

可以检查几组不同但重叠的数字字符。

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

s3.str.isdecimal 方法检查用来构成十进制数字的字符。

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

s.str.isdigit 方法与 s3.str.isdecimal 相同,但还包括特殊数字,例如Unicode中的上标和下标数字。

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

s.str.isnumeric 方法与 s3.str.isdigit 相同,但还包括其他可以表示数量的字符,例如 unicode 分数。

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

检查空白字符

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

检查字符大小写

>>> s5 = md.Series(['leopard', 'Golden Eagle', 'SNAKE', ''])
>>> s5.str.islower().execute()
0     True
1    False
2    False
3    False
dtype: bool
>>> s5.str.isupper().execute()
0    False
1    False
2     True
3    False
dtype: bool

s5.str.istitle 方法检查所有单词是否为标题格式(即每个单词的首字母是否大写)。单词被认为是任何由空白字符分隔的非数字字符的序列。

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