Skip to content

Commit 7301dbe

Browse files
JesperDramschvictor
authored and
victor
committed
DOC: Updating str_pad docstring (pandas-dev#22570)
1 parent e159369 commit 7301dbe

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

pandas/core/strings.py

+41-7
Original file line numberDiff line numberDiff line change
@@ -1332,23 +1332,57 @@ def str_index(arr, sub, start=0, end=None, side='left'):
13321332

13331333
def str_pad(arr, width, side='left', fillchar=' '):
13341334
"""
1335-
Pad strings in the Series/Index with an additional character to
1336-
specified side.
1335+
Pad strings in the Series/Index up to width.
13371336
13381337
Parameters
13391338
----------
13401339
width : int
13411340
Minimum width of resulting string; additional characters will be filled
1342-
with spaces
1341+
with character defined in `fillchar`.
13431342
side : {'left', 'right', 'both'}, default 'left'
1344-
fillchar : str
1345-
Additional character for filling, default is whitespace
1343+
Side from which to fill resulting string.
1344+
fillchar : str, default ' '
1345+
Additional character for filling, default is whitespace.
13461346
13471347
Returns
13481348
-------
1349-
padded : Series/Index of objects
1350-
"""
1349+
Series or Index of object
1350+
Returns Series or Index with minimum number of char in object.
1351+
1352+
See Also
1353+
--------
1354+
Series.str.rjust: Fills the left side of strings with an arbitrary
1355+
character. Equivalent to ``Series.str.pad(side='left')``.
1356+
Series.str.ljust: Fills the right side of strings with an arbitrary
1357+
character. Equivalent to ``Series.str.pad(side='right')``.
1358+
Series.str.center: Fills boths sides of strings with an arbitrary
1359+
character. Equivalent to ``Series.str.pad(side='both')``.
1360+
Series.str.zfill: Pad strings in the Series/Index by prepending '0'
1361+
character. Equivalent to ``Series.str.pad(side='left', fillchar='0')``.
1362+
1363+
Examples
1364+
--------
1365+
>>> s = pd.Series(["caribou", "tiger"])
1366+
>>> s
1367+
0 caribou
1368+
1 tiger
1369+
dtype: object
1370+
1371+
>>> s.str.pad(width=10)
1372+
0 caribou
1373+
1 tiger
1374+
dtype: object
13511375
1376+
>>> s.str.pad(width=10, side='right', fillchar='-')
1377+
0 caribou---
1378+
1 tiger-----
1379+
dtype: object
1380+
1381+
>>> s.str.pad(width=10, side='both', fillchar='-')
1382+
0 -caribou--
1383+
1 --tiger---
1384+
dtype: object
1385+
"""
13521386
if not isinstance(fillchar, compat.string_types):
13531387
msg = 'fillchar must be a character, not {0}'
13541388
raise TypeError(msg.format(type(fillchar).__name__))

0 commit comments

Comments
 (0)