Snippet
1 Upvote

Bag of Words DataFrame Using CountVectorizer

Python - NLP

CountVectorizer - bag of words

Here we use the CountVectorizer function from Sklearn to create a bag of words dataframe from the text column of an existing dataframe.
from sklearn.feature_extraction.text import CountVectorizer

count_vectorizer = CountVectorizer()
bag_of_words = count_vectorizer.fit_transform(df['text'])
bag_of_words = pd.DataFrame(bag_of_words.toarray(),columns = count_vectorizer.get_feature_names())

By analyseup - Last Updated Sept. 28, 2021, 10:42 a.m.

Comments
Related Snippets
Snippet
Upvotes
Creator