(df, col, type="count", **kwargs)
return unique.set_index(col)
Create count vectors using the sklearn TfidfVectorizer or CountVectorizer for the specified column in the given dataframe.
        The type argument can be "tfidf" referring to TfidfVectorizer, anything else defaults to CountVectorizer.
Create count vectors using the sklearn TfidfVectorizer or CountVectorizer for the specified column in the given dataframe.
        The type argument can be "tfidf" referring to TfidfVectorizer, anything else defaults to CountVectorizer.
Create count vectors using the sklearn TfidfVectorizer or CountVectorizer for the specified column in the given dataframe . The type argument can be tfidf referring to TfidfVectorizer anything else defaults to CountVectorizer .
def text_vectorizer(df, col, type="count", **kwargs):
        """
        Create count vectors using the sklearn TfidfVectorizer or CountVectorizer for the specified column in the given dataframe.
        The type argument can be "tfidf" referring to TfidfVectorizer, anything else defaults to CountVectorizer.
        """
        
        unique = pd.DataFrame(df[col].unique(), columns=[col])
        
        if type == "tfidf":
            v = TfidfVectorizer(**kwargs)
        else:
            v = CountVectorizer(**kwargs)
        
        vectorized = v.fit_transform(unique.loc[:, col])

        feature_names = v.get_feature_names()
        col_names = []

        for i,j in enumerate(feature_names):
            col_names.append("{}_{}".format(i,j))

        unique = unique.join(pd.DataFrame(vectorized.toarray(), columns=col_names).add_prefix(col+"_"))
        return unique.set_index(col)
def text_vectorizer ( df , col , type = "count" , * * kwargs ) : unique = pd . DataFrame ( df [ col ] . unique ( ) , columns = [ col ] ) if type == "tfidf" : v = TfidfVectorizer ( * * kwargs ) else : v = CountVectorizer ( * * kwargs ) vectorized = v . fit_transform ( unique . loc [ : , col ] ) feature_names = v . get_feature_names ( ) col_names = [ ] for i , j in enumerate ( feature_names ) : col_names . append ( "{}_{}" . format ( i , j ) ) unique = unique . join ( pd . DataFrame ( vectorized . toarray ( ) , columns = col_names ) . add_prefix ( col + "_" ) ) return unique . set_index ( col )