def featureScale(x, xRef=None):
    """Helper function to perform feature scaling.
    
    INPUTS:
    x: pandas DataFrame or Series.
    xRef: reference pandas DataFrame.
    
    If only x is provided, x will be normalized against itself.
    If xRef is additionally supplied, x will be normalized against xRef
    
    OUTPUTS:
    xPrime: pandas DataFrame (or Series, depending on type of x). Each column
        is scaled to that all values fall in the range [0, 1]
    """
    if xRef is None:
        xRef = x

    xPrime = (x - xRef.min()) / (xRef.max() - xRef.min())

    # If an entire column is NaN, zero it out.
    if len(xPrime.shape) > 1:
        # Pandas DataFrame (multi-dimensional)
        NaNSeries = xPrime.isnull().all()
    elif len(xPrime.shape) == 1:
        # Pandas Series (1-dimensional)
        NaNSeries = xPrime.isnull()
    else:
        raise UserWarning('Something went wrong in featureScale...')

    # Loop and zero out.
    for index in NaNSeries.index[NaNSeries]:
        xPrime[index] = 0

    return xPrime