@@ -2473,18 +2473,63 @@ def rjust(self, width, fillchar=' '):
2473
2473
2474
2474
def zfill (self , width ):
2475
2475
"""
2476
- Filling left side of strings in the Series/Index with 0.
2477
- Equivalent to :meth:`str.zfill`.
2476
+ Pad strings in the Series/Index by prepending '0' characters.
2477
+
2478
+ Strings in the Series/Index are padded with '0' characters on the
2479
+ left of the string to reach a total string length `width`. Strings
2480
+ in the Series/Index with length greater or equal to `width` are
2481
+ unchanged.
2478
2482
2479
2483
Parameters
2480
2484
----------
2481
2485
width : int
2482
- Minimum width of resulting string; additional characters will be
2483
- filled with 0
2486
+ Minimum length of resulting string; strings with length less
2487
+ than `width` be prepended with '0' characters.
2484
2488
2485
2489
Returns
2486
2490
-------
2487
- filled : Series/Index of objects
2491
+ Series/Index of objects
2492
+
2493
+ See Also
2494
+ --------
2495
+ Series.str.rjust: Fills the left side of strings with an arbitrary
2496
+ character.
2497
+ Series.str.ljust: Fills the right side of strings with an arbitrary
2498
+ character.
2499
+ Series.str.pad: Fills the specified sides of strings with an arbitrary
2500
+ character.
2501
+ Series.str.center: Fills boths sides of strings with an arbitrary
2502
+ character.
2503
+
2504
+ Notes
2505
+ -----
2506
+ Differs from :meth:`str.zfill` which has special handling
2507
+ for '+'/'-' in the string.
2508
+
2509
+ Examples
2510
+ --------
2511
+ >>> s = pd.Series(['-1', '1', '1000', 10, np.nan])
2512
+ >>> s
2513
+ 0 -1
2514
+ 1 1
2515
+ 2 1000
2516
+ 3 10
2517
+ 4 NaN
2518
+ dtype: object
2519
+
2520
+ Note that ``10`` and ``NaN`` are not strings, therefore they are
2521
+ converted to ``NaN``. The minus sign in ``'-1'`` is treated as a
2522
+ regular character and the zero is added to the left of it
2523
+ (:meth:`str.zfill` would have moved it to the left). ``1000``
2524
+ remains unchanged as it is longer than `width`.
2525
+
2526
+ >>> s.str.zfill(3)
2527
+ 0 0-1
2528
+ 1 001
2529
+ 2 1000
2530
+ 3 NaN
2531
+ 4 NaN
2532
+ dtype: object
2488
2533
"""
2489
2534
result = str_pad (self ._data , width , side = 'left' , fillchar = '0' )
2490
2535
return self ._wrap_result (result )
0 commit comments