Word Frequency Analysis - TypeError: '>=' not supported between instances of 'list' and 'int'
Word Frequency Analysis - TypeError: '>=' not supported between instances of 'list' and 'int'
我是 运行 Jupyter Notebook 上关于使用本网站进行词频分析的代码:http://theautomatic.net/2017/10/12/word-frequency-analysis/ ... 当我完成该过程时,当 运行 表示以下内容:
TypeError: '>=' not supported between instances of 'list' and 'int'.
基本上,我必须过滤掉至少 3 次没有提及 Netflix 的文章。
article_to_freq = {article:freq for article, freq in
article_to_freq.items() if freq >= 3}
错误似乎发生在这段代码的第 2 行:article_to_freq.items() if freq >= 3}
如前所述,我不断收到:
TypeError: '>=' not supported between instances of 'list' and 'int'
任何帮助将不胜感激,谢谢!
我假设问题是您正在比较 "freq" 这是一个列表(数组)和 3 这是一个整数(数字)。解决方案是使用 len(freq) 将数组的长度与数字 3 进行比较,如下例所示:
#random example of the list
freq =[1,2,3,4,5,6,7]
#you use len() to get the length of the array
if len(freq) >= 3:
print(freq) #or do what ever it is you want to do with it
希望对您有所帮助
我是 运行 Jupyter Notebook 上关于使用本网站进行词频分析的代码:http://theautomatic.net/2017/10/12/word-frequency-analysis/ ... 当我完成该过程时,当 运行 表示以下内容:
TypeError: '>=' not supported between instances of 'list' and 'int'.
基本上,我必须过滤掉至少 3 次没有提及 Netflix 的文章。
article_to_freq = {article:freq for article, freq in
article_to_freq.items() if freq >= 3}
错误似乎发生在这段代码的第 2 行:article_to_freq.items() if freq >= 3}
如前所述,我不断收到:
TypeError: '>=' not supported between instances of 'list' and 'int'
任何帮助将不胜感激,谢谢!
我假设问题是您正在比较 "freq" 这是一个列表(数组)和 3 这是一个整数(数字)。解决方案是使用 len(freq) 将数组的长度与数字 3 进行比较,如下例所示:
#random example of the list
freq =[1,2,3,4,5,6,7]
#you use len() to get the length of the array
if len(freq) >= 3:
print(freq) #or do what ever it is you want to do with it
希望对您有所帮助