@@ -1332,23 +1332,57 @@ def str_index(arr, sub, start=0, end=None, side='left'):
1332
1332
1333
1333
def str_pad (arr , width , side = 'left' , fillchar = ' ' ):
1334
1334
"""
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.
1337
1336
1338
1337
Parameters
1339
1338
----------
1340
1339
width : int
1341
1340
Minimum width of resulting string; additional characters will be filled
1342
- with spaces
1341
+ with character defined in `fillchar`.
1343
1342
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.
1346
1346
1347
1347
Returns
1348
1348
-------
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
1351
1375
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
+ """
1352
1386
if not isinstance (fillchar , compat .string_types ):
1353
1387
msg = 'fillchar must be a character, not {0}'
1354
1388
raise TypeError (msg .format (type (fillchar ).__name__ ))
0 commit comments