def __prep_importance(
    df_vim_structured, s_vim_importance, style="tail", shadow="null",
    num_features=50):
    """Given a DataFrame containing the structured VIM scores and a Series
    containing mean VIMs, finds the n head or tail features (and the top
    shadow, if it's not among the n), and returns the columns of
    df_vim_structured for those features.
    """
    s_sorted = s_vim_importance.copy()
    s_sorted.sort_values(inplace=True)

    # subset the top or bottom features
    s_truncated = None
    if style is 'tail':
        # gives us the names of the n best features
        s_truncated = s_sorted.tail(num_features)
    else:
        # gives us the names of the n worst features
        s_truncated = s_sorted.head(num_features)

    # ensure that the passed shadow feature is included
    if shadow and shadow not in s_truncated:
        s_truncated[shadow] = s_sorted[shadow]

    return df_vim_structured[s_truncated.index]