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

Method strip

pandas/core/strings/accessor.py:2473–2550  ·  view source on GitHub ↗

Remove leading and trailing characters. Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from left and right sides. Replaces any non-strings in Series with NaNs. Equivalent to :meth:`str.strip`.

(self, to_strip=None)

Source from the content-addressed store, hash-verified

2471
2472 @forbid_nonstring_types(["bytes"])
2473 def strip(self, to_strip=None):
2474 """
2475 Remove leading and trailing characters.
2476
2477 Strip whitespaces (including newlines) or a set of specified characters
2478 from each string in the Series/Index from left and right sides.
2479 Replaces any non-strings in Series with NaNs.
2480 Equivalent to :meth:`str.strip`.
2481
2482 Parameters
2483 ----------
2484 to_strip : str or None, default None
2485 Specifying the set of characters to be removed.
2486 All combinations of this set of characters will be stripped.
2487 If None then whitespaces are removed.
2488
2489 Returns
2490 -------
2491 Series or Index of object
2492 Series or Index with the strings being stripped from the left and
2493 right sides.
2494
2495 See Also
2496 --------
2497 Series.str.strip : Remove leading and trailing characters in Series/Index.
2498 Series.str.lstrip : Remove leading characters in Series/Index.
2499 Series.str.rstrip : Remove trailing characters in Series/Index.
2500
2501 Examples
2502 --------
2503 >>> s = pd.Series(["1. Ant. ", "2. Bee!\\n", "3. Cat?\\t", np.nan, 10, True])
2504 >>> s
2505 0 1. Ant.
2506 1 2. Bee!\\n
2507 2 3. Cat?\\t
2508 3 NaN
2509 4 10
2510 5 True
2511 dtype: object
2512
2513 >>> s.str.strip()
2514 0 1. Ant.
2515 1 2. Bee!
2516 2 3. Cat?
2517 3 NaN
2518 4 NaN
2519 5 NaN
2520 dtype: object
2521
2522 >>> s.str.lstrip("123.")
2523 0 Ant.
2524 1 Bee!\\n
2525 2 Cat?\\t
2526 3 NaN
2527 4 NaN
2528 5 NaN
2529 dtype: object
2530

Callers 15

conda_package_to_pipFunction · 0.80
get_toml_map_fromFunction · 0.80
get_yaml_map_fromFunction · 0.80
clean_version_listFunction · 0.80
get_versions_from_ciFunction · 0.80
get_versions_from_tomlFunction · 0.80
mainFunction · 0.80
get_api_itemsFunction · 0.80
validate_pep8Method · 0.80

Calls 2

_wrap_resultMethod · 0.95
_str_stripMethod · 0.45