Python 如何为数据帧中的列创建反向索引?

Python 如何为数据帧中的列创建反向索引?,python,dataframe,nlp,nltk,tf-idf,Python,Dataframe,Nlp,Nltk,Tf Idf,我为我的刮取的数据创建了一个数据框,删除了标点符号、停止字并对其进行了标记。 如何为列名称和品牌创建反向索引 import nltk import string from nltk.corpus import stopwords from nltk.tokenize import RegexpTokenizer from nltk.stem import WordNetLemmatizer import pandas as pd 请编辑问题以直接包含代码,而不是作为图像或链接。 tokens

我为我的刮取的数据创建了一个数据框,删除了标点符号、停止字并对其进行了标记。 如何为列名称和品牌创建反向索引

import nltk
import string
from nltk.corpus import stopwords
from nltk.tokenize import RegexpTokenizer
from nltk.stem import WordNetLemmatizer
import pandas as pd

请编辑问题以直接包含代码,而不是作为图像或链接。
tokens = RegexpTokenizer(r'\w+')
macys_df['name'] = macys_df['name'].apply(lambda x: tokens.tokenize(x.lower()))
macys_df.head()
stop_words = set(stopwords.words('english')) 
stop_words = stop_words.union(",","(",")","[","]","{","}","#","@","!",":",";",".","?")

macys_df['name'] = macys_df['name'].apply(lambda x: [item for item in x if item not in stop_words])
Output - 
macys_df['name'].head()
0    [versa, 2, black, elastomer, strap, touchscree...
1    [men, digital, black, resin, strap, watch, 50,...
2      [versa, lite, white, strap, smart, watch, 39mm]
3    [access, mkgo, black, silicone, strap, touchsc...
4    [inspire, black, strap, activity, tracker, 19,...