【发布时间】:2021-03-08 20:16:24
【问题描述】:
我想使用 juypter notebook 应用情绪分析, 这是我的代码
pos_list = positive_words['Positive'].values.tolist()
def pos_sentiment(推文): 计数=0 对于 pos_list 中的单词: 如果推文中的单词: 计数+=1 返回计数
clean_data['pos_count'] = clean_data['tweetText'].apply(lambda x: pos_sentiment(x))
出现此错误
TypeError Traceback(最近一次调用最后一次) 在 ----> 1 clean_data['pos_count'] = clean_data['tweetText'].apply(lambda x: pos_sentiment(x))
~\anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds) 4198 其他: 4199 值 = self.astype(object)._values -> 4200 映射 = lib.map_infer(values, f, convert=convert_dtype) 4201 4202 if len(mapped) and isinstance(mapped[0], Series):
pandas_libs\lib.pyx in pandas._libs.lib.map_infer()
在 (x) ----> 1 clean_data['pos_count'] = clean_data['tweetText'].apply(lambda x: pos_sentiment(x))
in pos_sentiment(tweet) 2 计数=0 3 用于 pos_list 中的单词: ----> 4 如果推文中的单词: 5 计数+=1 6返回计数
TypeError: 'float' 类型的参数不可迭代
【问题讨论】:
标签: python function jupyter-notebook anaconda typeerror