Pad strings in the Series/Index up to width.

    Parameters
    ----------
    width : int
        Minimum width of resulting string; additional characters will be filled
        with character defined in `fillchar`.
    side : {'left', 'right', 'both'}, default 'left'
        Side from which to fill resulting string.
    fillchar : str, default ' '
        Additional character for filling, default is whitespace.

    Returns
    -------
    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 ``Series.str.pad(side='left')``.
    Series.str.ljust : Fills the right side of strings with an arbitrary
        character. Equivalent to ``Series.str.pad(side='right')``.
    Series.str.center : Fills boths sides of strings with an arbitrary
        character. Equivalent to ``Series.str.pad(side='both')``.
    Series.str.zfill :  Pad strings in the Series/Index by prepending '0'
        character. Equivalent to ``Series.str.pad(side='left', fillchar='0')``.

    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

def str_pad(arr, width, side='left', fillchar=' '):
    """
    Pad strings in the Series/Index up to width.

    Parameters
    ----------
    width : int
        Minimum width of resulting string; additional characters will be filled
        with character defined in `fillchar`.
    side : {'left', 'right', 'both'}, default 'left'
        Side from which to fill resulting string.
    fillchar : str, default ' '
        Additional character for filling, default is whitespace.

    Returns
    -------
    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 ``Series.str.pad(side='left')``.
    Series.str.ljust : Fills the right side of strings with an arbitrary
        character. Equivalent to ``Series.str.pad(side='right')``.
    Series.str.center : Fills boths sides of strings with an arbitrary
        character. Equivalent to ``Series.str.pad(side='both')``.
    Series.str.zfill :  Pad strings in the Series/Index by prepending '0'
        character. Equivalent to ``Series.str.pad(side='left', fillchar='0')``.

    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, str):
        msg = 'fillchar must be a character, not {0}'
        raise TypeError(msg.format(type(fillchar).__name__))

    if len(fillchar) != 1:
        raise TypeError('fillchar must be a character, not str')

    if not is_integer(width):
        msg = 'width must be of integer type, not {0}'
        raise TypeError(msg.format(type(width).__name__))

    if side == 'left':
        f = lambda x: x.rjust(width, fillchar)
    elif side == 'right':
        f = lambda x: x.ljust(width, fillchar)
    elif side == 'both':
        f = lambda x: x.center(width, fillchar)
    else:  # pragma: no cover
        raise ValueError('Invalid side')

    return _na_map(f, arr)