text_plain_output_1.png
from sklearn.feature_extraction.text import TfidfVectorizer

import operator

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

data = pd.read_csv('../input/winemag-data_first150k.csv')

df = data.dropna(subset=['description'])  # drop all NaNs

df_sorted = df.sort_values(by='points', ascending=True)  # sort by points

num_of_wines = df_sorted.shape[0]  # number of wines
worst = df_sorted.head(int(0.25*num_of_wines))  # 25 % of worst wines listed
best = df_sorted.tail(int(0.25*num_of_wines))  # 25 % of best wines listed

from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer(stop_words='english', analyzer='word')

X1 = vectorizer.fit_transform(best['description'])
idf = vectorizer.idf_
goodlist = vectorizer.vocabulary_

X = vectorizer.fit_transform(worst['description'])
idf = vectorizer.idf_
not_so_good_list = vectorizer.vocabulary_

import operator
sorted_good = sorted(goodlist.items(), key=operator.itemgetter(0))
sorted_bad = sorted(not_so_good_list.items(), key=operator.itemgetter(1), reverse=True)

sorted_good