def reduce_terms(df_frequency, max_df=1.0, min_df=1, max_terms=None, keep_less_freq=False):
    """Remove unimportant terms from term-by-document matrix.

    Parameters
    ----------
    df_frequency : pd.DataFrame
    max_df : float , between [0, 1]
             Terms that appear in more % of documents will be ignored
    min_df : int
             Terms that appear in <= number of documents will be ignored
    max_terms : int , None
                If not None or 0, only top `max_terms` terms will be returned.
    keep_less_freq : bool
                Decides wherever to keep most frequent or least frequent words when `max_terms` < len.
    """
    df = df_frequency.copy()
    corpus_size = df.shape[1]

    df['doc_apperance'] = df.fillna(0).astype(bool).sum(axis=1)
    df['doc_frequency'] = df['doc_apperance'] / corpus_size
            
    df = df[df.doc_frequency <= max_df]
    df = df[df.doc_apperance > min_df]
    
    if max_terms is not None and max_terms != 0 and max_terms < df.shape[0]:
        df = df.sort_values('doc_frequency', ascending=keep_less_freq)
        df = df.head(max_terms)

    return df.drop('doc_apperance', axis=1)