如何获得频率大于的单词列表?

2024-09-29 19:18:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经从数据框中创建了一个单词列表,并从中删除了停止词。 我想创建一个词频大于某个值n的单词列表。 我该怎么做

Here is my code to generate the list:

tokenizer = RegexpTokenizer(r"\w+(?:[-']\w+)?")
wineData['description'] = wineData['description'].apply(lambda x: 
str.lower(x))
wineDataTokenized = wineData['description'].apply(lambda x: [el for el in 
tokenizer.tokenize(x) if el not in stop_words])
filteredList = chain.from_iterable(wineDataTokenized)
frequencyList = FreqDist(filteredList)
highFreq = list(frequencyList.keys())

Tags: 数据lambdain列表description单词ellist
1条回答
网友
1楼 · 发布于 2024-09-29 19:18:42
wordstring = 'it was the best of times it was the worst of times '
wordstring += 'it was the age of wisdom it was the age of foolishness'
wordlist = wordstring.split()

wordfreq = []
for w in wordlist:
    wordfreq.append(wordlist.count(w))

print("String\n" + wordstring +"\n")
print("List\n" + str(wordlist) + "\n")
print("Frequencies\n" + str(wordfreq) + "\n")
print("Pairs\n" + str(zip(wordlist, wordfreq)))

资料来源:https://programminghistorian.org/en/lessons/counting-frequencies

相关问题 更多 >

    热门问题