MCPcopy
hub / github.com/pandas-dev/pandas / endswith

Method endswith

pandas/core/strings/accessor.py:3177–3236  ·  view source on GitHub ↗

Test if the end of each string element matches a pattern. Equivalent to :meth:`str.endswith`. Parameters ---------- pat : str or tuple[str, ...] Character sequence or tuple of strings. Regular expressions are not accepted. na

(
        self, pat: str | tuple[str, ...], na: Scalar | lib.NoDefault = lib.no_default
    )

Source from the content-addressed store, hash-verified

3175
3176 @forbid_nonstring_types(["bytes"])
3177 def endswith(
3178 self, pat: str | tuple[str, ...], na: Scalar | lib.NoDefault = lib.no_default
3179 ) -> Series | Index:
3180 """
3181 Test if the end of each string element matches a pattern.
3182
3183 Equivalent to :meth:`str.endswith`.
3184
3185 Parameters
3186 ----------
3187 pat : str or tuple[str, ...]
3188 Character sequence or tuple of strings. Regular expressions are not
3189 accepted.
3190 na : scalar, optional
3191 Object shown if element tested is not a string. The default depends
3192 on dtype of the array. For the ``"str"`` dtype, ``False`` is used.
3193 For object dtype, ``numpy.nan`` is used. For the nullable
3194 ``StringDtype``, ``pandas.NA`` is used.
3195
3196 Returns
3197 -------
3198 Series or Index of bool
3199 A Series of booleans indicating whether the given pattern matches
3200 the end of each string element.
3201
3202 See Also
3203 --------
3204 str.endswith : Python standard library string method.
3205 Series.str.startswith : Same as endswith, but tests the start of string.
3206 Series.str.contains : Tests if string element contains a pattern.
3207
3208 Examples
3209 --------
3210 >>> s = pd.Series(["bat", "bear", "caT", np.nan])
3211 >>> s
3212 0 bat
3213 1 bear
3214 2 caT
3215 3 NaN
3216 dtype: str
3217
3218 >>> s.str.endswith("t")
3219 0 True
3220 1 False
3221 2 False
3222 3 False
3223 dtype: bool
3224
3225 >>> s.str.endswith(("t", "T"))
3226 0 True
3227 1 False
3228 2 True
3229 3 False
3230 dtype: bool
3231 """
3232 if not isinstance(pat, (str, tuple)):
3233 msg = f"expected a string or tuple, not {type(pat).__name__}"
3234 raise TypeError(msg)

Callers 15

mainFunction · 0.80
mainFunction · 0.80
render_templatesMethod · 0.80
setup.pyFile · 0.80
has_wrong_whitespaceFunction · 0.80
time_endswithMethod · 0.80
__init__Method · 0.80
remove_flags_docstringFunction · 0.80
runMethod · 0.80

Calls 2

_wrap_resultMethod · 0.95
_str_endswithMethod · 0.45

Tested by 15

ignore_doctest_warningFunction · 0.64
check_fun_dataMethod · 0.64
check_funMethod · 0.64
test_endswithFunction · 0.64
test_empty_str_methodsFunction · 0.64
create_blockFunction · 0.64
test_read_fspath_allMethod · 0.64
convert_daysFunction · 0.64
convert_days_sentinelFunction · 0.64