这是我的代码
import nltk
freq_dist = nltk.FreqDist(words)
print freq_dist.keys()[:50] # 50 most frequent tokens
print freq_dist.keys()[-50:] # 50 least frequent tokens
我收到此错误消息:
ImportError:无法导入名称compat
答案 0 :(得分:1)
当你可能只需要一小部分时,你试图导入整个nltk。尝试编辑代码
from nltk import FreqDist
freq_dist = FreqDist(words)
print freq_dist.keys()[:50] # 50 most frequent tokens
print freq_dist.keys()[-50:] # 50 least frequent tokens