maxframe.dataframe.Series.str.startswith#

Series.str.startswith(pat: str | tuple[str, ...], na: Scalar | lib.NoDefault = <no_default>) Series | Index#

测试每个字符串元素的开头是否匹配某个模式。

等价于 str.startswith()

参数:
  • pat (str or tuple[str, ...]) -- 字符序列或字符串元组。不接受正则表达式。

  • na (scalar, optional) -- Object shown if element tested is not a string. The default depends on dtype of the array. For the "str" dtype, False is used. For object dtype, numpy.nan is used. For the nullable StringDtype, pandas.NA is used.

返回:

一个布尔值 Series,指示给定模式是否匹配每个字符串元素的开头。

返回类型:

Series or Index of bool

参见

str.startswith

Python 标准库字符串方法。

Series.str.endswith

与 startswith 相同,但测试字符串的结尾。

Series.str.contains

测试字符串元素是否包含某个模式。

示例

>>> import maxframe.tensor as mt
>>> import maxframe.dataframe as md
>>> s = md.Series(["bat", "Bear", "cat", mt.nan])
>>> s.execute()
0     bat
1    Bear
2     cat
3     NaN
dtype: str
>>> s.str.startswith("b").execute()
0     True
1    False
2    False
3    False
dtype: bool
>>> s.str.startswith(("b", "B")).execute()
0     True
1     True
2    False
3    False
dtype: bool