-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Updating str_pad docstring #22570
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 12 commits
52bc395
5d5b192
28ec7b0
8337a53
0224b12
763f3c3
50940c8
c473a4f
6f6853e
7456656
f2d221d
0640204
c785311
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 |
---|---|---|
|
@@ -1314,23 +1314,57 @@ def str_index(arr, sub, start=0, end=None, side='left'): | |
|
||
def str_pad(arr, width, side='left', fillchar=' '): | ||
""" | ||
Pad strings in the Series/Index with an additional character to | ||
specified side. | ||
Pad strings in the Series/Index up to width. | ||
|
||
Parameters | ||
---------- | ||
width : int | ||
Minimum width of resulting string; additional characters will be filled | ||
with spaces | ||
with character defined in fillchar. | ||
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. Can you add backticks around |
||
side : {'left', 'right', 'both'}, default 'left' | ||
fillchar : str | ||
Additional character for filling, default is whitespace | ||
Side from which to fill resulting string. | ||
fillchar : str, default ' ' | ||
Additional character for filling, default is whitespace. | ||
|
||
Returns | ||
------- | ||
padded : Series/Index of objects | ||
""" | ||
Series or Index of object | ||
Returns Series or Index with minimum number of char in object. | ||
|
||
See Also | ||
-------- | ||
Series.str.rjust: Fills the left side of strings with an arbitrary | ||
character. Equivalent to pd.str.pad(side='left'). | ||
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. it's not really |
||
Series.str.ljust: Fills the right side of strings with an arbitrary | ||
character. Equivalent to pd.str.pad(side='right'). | ||
Series.str.center: Fills boths sides of strings with an arbitrary | ||
character. Equivalent to pd.str.pad(side='both'). | ||
Series.str.zfill: Pad strings in the Series/Index by prepending '0' | ||
character. Equivalent to pd.str.pad(side='right', fillchar='0'). | ||
|
||
JesperDramsch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(["caribou", "tiger"]) | ||
>>> s | ||
0 caribou | ||
1 tiger | ||
dtype: object | ||
|
||
>>> s.str.pad(width=10) | ||
0 caribou | ||
1 tiger | ||
dtype: object | ||
|
||
>>> s.str.pad(width=10, side='right', fillchar='-') | ||
0 caribou--- | ||
1 tiger----- | ||
dtype: object | ||
|
||
>>> s.str.pad(width=10, side='both', fillchar='-') | ||
0 -caribou-- | ||
1 --tiger--- | ||
dtype: object | ||
""" | ||
if not isinstance(fillchar, compat.string_types): | ||
msg = 'fillchar must be a character, not {0}' | ||
raise TypeError(msg.format(type(fillchar).__name__)) | ||
|
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.
I think in this case we could have a extended summary, providing a bit more information on what pad means, and when it can be useful.