text_plain_output_1.png
import nltk

import pandas as pd

df = pd.read_csv('/kaggle/input/online-retails-sale-dataset/Online Retail.csv')

import nltk
sc = df.copy()[['StockCode', 'Description']]
sc.dropna(inplace=True)
sc.Description = sc.Description.str.lower()
items = sc.groupby('StockCode').Description.unique()
items = list(zip(items.index.tolist(), items.values.tolist()))
clean_items = []
for x in items:
    temp = x[1]
    if len(temp) > 1:
        clean_items.append((x[0], x[1][0]))
    else:
        clean_items.append(x)
descs = [x[1].tolist() for x in clean_items]
tks = [nltk.word_tokenize(x[0]) for x in descs]
descs_p = []
for x in tks:
    temp = nltk.pos_tag(x)
    new_desc = []
    for y in temp:
        word, tag = y
        if tag.startswith('N'):
            new_desc.append(word)
        else:
            pass
    descs_p.append(new_desc)
print(descs_p[:25])