text_html_output_1.png
from nltk.corpus import stopwords

from sklearn.feature_extraction.text import TfidfVectorizer

import pandas as pd

import string

df = pd.DataFrame(pd.read_csv('../input/spam.csv', encoding='latin-1')[['v1', 'v2']])
df.columns = ['Label', 'Message']

df.groupby('Label').describe()

def process(text):
    text = text.lower()
    text = ''.join([t for t in text if t not in string.punctuation])
    text = [t for t in text.split() if t not in stopwords.words('english')]
    st = Stemmer()
    text = [st.stem(t) for t in text]
    return text

tfidfv = TfidfVectorizer(analyzer=process)
data = tfidfv.fit_transform(df['Message'])

mess = df.iloc[2]['Message']

print(tfidfv.transform([mess]))