def limitedSubs(data, max_interp=3, func=lambda x: abs(x) > abs(x.std() * 4.0)
    ):
    """
    Substitute elements for NaNs if a certain conditions given by fund is met at 
    a maximum of max_interp times in a row.
    If there are more than that number in a row, then they are not substituted.

    Parameters
    -----------
    data: pandas.dataframe
        data to be interpolated
    max_interp: int
        number of maximum NaNs in a row to interpolate
    func: function
        function of x only that determines the which elements become NaNs. Should return
        only True or False.

    Returns
    --------
    df: pandas.dataframe
        dataframe with the elements substituted
    """
    import numpy as np
    df = data.copy()
    cond = func(df)
    for c in df.columns:
        grouper = (cond[c] != cond[c].shift(1)).cumsum() * cond[c]
        fill = df.groupby(grouper)[c].transform(lambda x: x.size) <= max_interp
        df.loc[fill & cond[c], c] = np.nan
    return df
