python - TypeError:“float”对象在 Pandas Dataframe Python 中不可迭代
问题描述
我要做的是在名为“名词”的数据框中创建一个新列,并保留我已从中删除停用词的列中的所有名词。
问题是在我正在使用的药物数据集中,药物评论列中的某处必须有浮动对象,因为它不会让我对其进行迭代。我读到我可以使用 range() 但我不确定这将如何转化为我的循环,因为我不确定范围而且我读到 .dropna 可以工作但据我所知没有空值在任何行中。
我的代码:
df['nouns'] = df.apply(lambda row: nltk.word_tokenize(row['noStopwordsReview']), axis=1)
noun=[]
for index, row in df.iterrows():
noun.append([word for word,pos in pos_tag(row[0]) if pos == 'NN'])
df['nouns'] = noun
完整的追溯:
回溯(最近一次通话最后):
File "/Users/matthewrook/OneDrive - AUT University/Year 3/Data Mining/assignment1.py", line 76, in <module>
noun.append([word for word,pos in pos_tag(row[0]) if pos == 'NN'])
File "/opt/anaconda3/lib/python3.8/site-packages/nltk/tag/__init__.py", line 161, in pos_tag
return _pos_tag(tokens, tagset, tagger, lang)
File "/opt/anaconda3/lib/python3.8/site-packages/nltk/tag/__init__.py", line 118, in _pos_tag
tagged_tokens = tagger.tag(tokens)
File "/opt/anaconda3/lib/python3.8/site-packages/nltk/tag/perceptron.py", line 181, in tag
context = self.START + [self.normalize(w) for w in tokens] + self.END
TypeError: 'float' object is not iterable
解决方案
推荐阅读
- drupal-8 - 自定义模块不适用于自定义引导子主题 - Drupal 8
- amazon-web-services - 错误消息 = 进程在完成请求之前退出。错误 = 池已关闭
- ruby-on-rails - Rails - 如何运行 Helpy 应用程序?
- c# - 使用 WebClient 时如何绕过系统代理
- excel - 如何将数据引用到不同的工作表(主工作表中的范围单元格不同)
- android - 应用程序使用一段时间后进入后台
- ios - UICollectionView 动画不显示数据
- android - android - 无法获取位置坐标
- single-sign-on - .NET 4.0 WSFed 应用程序在成功验证后仅在 IE 中继续重定向到 ADFS
- r - 在 R 中的“summary(aov)”的输出中添加一列?