TF-IDF With scikit-learn
Vectorize a corpus in a few lines.
No Need to Hand-Code It
You understand the math, so now let scikit-learn do the heavy lifting. Its TfidfVectorizer turns raw documents into a weighted matrix in a few lines.
Import the Vectorizer
Everything lives in the feature_extraction.text module. Import TfidfVectorizer and you are ready to vectorize any list of text strings.
from sklearn.feature_extraction.text import TfidfVectorizer