-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Improve the docstring of String.str.zfill() #20864
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
Changes from 2 commits
1e16540
b89cd54
6669889
07f4189
8034856
60ea781
4a54a66
706688f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2114,19 +2114,55 @@ def rjust(self, width, fillchar=' '): | |
|
||
def zfill(self, width): | ||
""" | ||
Filling left side of strings in the Series/Index with 0. | ||
Equivalent to :meth:`str.zfill`. | ||
Pad strings in the Series/Index by prepending '0' characters. | ||
|
||
Strings in the Series/Index are padded with prepending '0' characeters | ||
(i.e. on the left of the string) to reach a total string length | ||
of `width`. in the Series/Index with length greater than `width` | ||
are unchanged. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think something went wrong with that last sentence, two spaces, not starting with a capital letter, and I think it's not that clear, a word or something is missing I guess. |
||
|
||
Note: Differs from :meth:`str.zfill` which has special handling | ||
for '+'/'-' in the string. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a
https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-6-notes |
||
|
||
Parameters | ||
---------- | ||
width : int | ||
Minimum width of resulting string; additional characters will be | ||
filled with 0 | ||
Minimum length of resulting string; strings with length less | ||
than `width` be prepended with '0' characters. | ||
|
||
Returns | ||
------- | ||
filled : Series/Index of objects | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can get rid of the |
||
|
||
See Also | ||
-------- | ||
Series.str.rjust: Fills the left side of strings with an arbitrary | ||
character. | ||
Series.str.ljust: Fills the right side of strings with an arbitrary | ||
character. | ||
Series.str.pad: Fills the specified sides of strings with an arbitrary | ||
character. | ||
Series.str.center: Fills boths sides of strings with an arbitrary | ||
character. | ||
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(['-2', '+5', '10', '127', '423523']) | ||
>>> s.str.zfill(5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great now. Just couple of ideas, feel free to ignore them if you prefer the way it is now. I think it could be useful to add a short paragraph before this line explaining that the non-string values ( I also think that it would make things easier/faster to understand if the values look a bit less arbitrary. For example |
||
0 000-2 | ||
1 000+5 | ||
2 00010 | ||
3 00127 | ||
4 423523 | ||
dtype: object | ||
|
||
>>> s = pd.Series([-2, 5], dtype=str) | ||
>>> s.str.zfill(5) | ||
0 000-2 | ||
1 00005 | ||
dtype: object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the example looks cool, but I think we can make it a bit more compact and clear by:
|
||
""" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to add this blank line here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to add this blank line. |
||
result = str_pad(self._data, width, side='left', fillchar='0') | ||
return self._wrap_result(result) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in
characters