Skip to content

Added example for num and bool to pandas.Series.str.strip #44885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion pandas/core/strings/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,8 @@ def encode(self, encoding, errors="strict"):

See Also
--------
Series.str.strip : Remove leading and trailing characters in Series/Index.
Series.str.strip : Remove leading and trailing characters in Series/Index,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wouldn't add any of this, instead you can add in a Notes section a line.

it also replaces numeric and bool values with NaN.
Series.str.lstrip : Remove leading characters in Series/Index.
Series.str.rstrip : Remove trailing characters in Series/Index.

Expand Down Expand Up @@ -1935,6 +1936,31 @@ def encode(self, encoding, errors="strict"):
2 Cat
3 NaN
dtype: object

s = pd.Series(['hello ', ' goodbye', 1.0, 0.0, 1, 0, True, False, np.nan])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use other numbers int(True) is 1 and int(False) is 0

>>> s
0 hello
1 goodbye
2 1.0
3 0.0
4 1
5 0
6 True
7 False
8 NaN
dtype: object

>>> s.str.strip()
0 hello
1 goodbye
2 NaN
3 NaN
4 NaN
5 NaN
6 NaN
7 NaN
8 NaN
dtype: object
"""

@Appender(
Expand Down