text_html_output_1.png
from sklearn.feature_extraction.text import CountVectorizer

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

sentences = ['This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document?']

cv = CountVectorizer()

X = cv.fit_transform(sentences)
X.toarray()

cv.get_feature_names_out()

pd.DataFrame(cv.get_feature_names_out())

cv = CountVectorizer(ngram_range=(2, 2))

X = cv.fit_transform(sentences)
X.toarray()

cv.get_feature_names_out()

pd.DataFrame(cv.get_feature_names_out())

cv = CountVectorizer(ngram_range=(1, 2))

X = cv.fit_transform(sentences)
X.toarray()