首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python教程帮助NLP客户评审

Python教程帮助NLP客户评审
EN

Stack Overflow用户
提问于 2019-09-24 16:58:40
回答 1查看 68关注 0票数 0

我对Python相当陌生,我正在学习基于客户评论文件创建wordcloud的教程。教程链接是https://towardsdatascience.com/detecting-bad-customer-reviews-with-nlp-d8b36134dc7e

代码语言:javascript
复制
from wordcloud import WordCloud, STOPWORDS
import pandas as pd

# read data
reviews_df = pd.read_csv("Hotel_Reviews3.csv")
# append the positive and negative text reviews
reviews_df["review"] = reviews_df["Negative_Review"] + reviews_df["Positive_Review"]

# create the label
reviews_df["is_bad_review"] = reviews_df["Reviewer_Score"].apply(lambda x: 1 if x < 5 else 0)

# select only relevant columns
reviews_df = reviews_df[["review", "is_bad_review"]]
reviews_df.head()

Hotel_Reviews3.csv:https://i.stack.imgur.com/8ZGxj.png

错误消息

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\stecd\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\indexes\base.py", line 3078, in get_loc
    return self._engine.get_loc(key)
  File "pandas\_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Positive_Review'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\stecd\Desktop\WorldCloud\wordCloud.py", line 6, in <module>
    reviews_df["review"] = reviews_df["Negative_Review"] + reviews_df["Positive_Review"]
  File "C:\Users\stecd\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py", line 2688, in __getitem__
    return self._getitem_column(key)
  File "C:\Users\stecd\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py", line 2695, in _getitem_column
    return self._get_item_cache(key)
  File "C:\Users\stecd\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\generic.py", line 2489, in _get_item_cache
    values = self._data.get(item)
  File "C:\Users\stecd\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\internals.py", line 4115, in get
    loc = self.items.get_loc(item)
  File "C:\Users\stecd\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\indexes\base.py", line 3080, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
  File "pandas\_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Positive_Review'
>>> 
EN

回答 1

Stack Overflow用户

发布于 2019-09-24 18:51:47

从错误消息中,我猜Hotel_Reviews3.csv可能没有"Positive_Review"列。可能是相应的表条目被截断或具有空白,因此它与"Positive_Review"不匹配。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58085041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档