def semideviation(r):
    '\n    Returns the semideviation aka negative semideviation of r\n    r must be a Series or a DataFrame, else raises a TypeError\n    '
    if isinstance(r, pd.Series):
        is_negative = (r < 0)
        return r[is_negative].std(ddof=0)
    elif isinstance(r, pd.DataFrame):
        return r.aggregate(semideviation)
    else:
        raise TypeError('Expected r to be a Series or DataFrame')
Returns the semideviation aka negative semideviation of r
r must be a Series or a DataFrame, else raises a TypeError
def semideviation(r):
    '\n    Returns the semideviation aka negative semideviation of r\n    r must be a Series or a DataFrame, else raises a TypeError\n    '
    if isinstance(r, pd.Series):
        is_negative = (r < 0)
        return r[is_negative].std(ddof=0)
    elif isinstance(r, pd.DataFrame):
        return r.aggregate(semideviation)
    else:
        raise TypeError('Expected r to be a Series or DataFrame')