【发布时间】:2020-08-24 22:50:23
【问题描述】:
给定一个 csv 文件。我希望变量 good_words 包含 CleanedText 列中的所有单词。但它显示以下错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
CleanedText 列包含使用 nltk 删除停用词后获得的所有单词。
good_words = []
if edata3['class']=='good':
good_words = edata3.loc[0: , 'CleanedText']
前面的代码块是:
import os
if os.path.isfile(r'/Users/vivekbhadula/study/cleaned_final.db'):
conn = sqlite3.connect(r'/Users/vivekbhadula/study/cleaned_final.db')
final = edata2['CleanedText']
edata3 = edata2.copy()
edata3.append(final)
else:
print('Please run the above cell')
edata3.head() 的输出是:
**Clothing ID|| Age ||Title || Review_Text|| Rating|| Recommended_IND || Positive_Feedback_Count || Division_Name|| Department_Name ||Class_Name|| class|| CleanedText**
2 1077|| 60 ||Some major design flaws || I had such high hopes for this dress and reall... ||3 ||0 ||0 ||General|| Dresses ||Dresses|| bad high hope dress realli want work initi order p...
3 1049 50 My favorite buy! I love, love, love this jumpsuit. it's fun, fl... 5 1 0 General Petite Bottoms Pants good love love love jumpsuit fun flirti everi time ...
4 847 47 Flattering shirt This shirt is very flattering to all due to th... 5 1 6 General Tops Blouses good shirt flatter due adjust front tie perfect len...
5 1080 49 Not for the very petite I love tracy reese dresses, but this one is no... 2 0 4 General Dresses Dresses bad love traci rees dress one petit feet tall usua...
6 858 39 Cagrcoal shimmer fun I aded this in my basket at hte last mintue to... 5 1 1 General Petite Tops Knits good ade basket hte last mintu see would look like ...
【问题讨论】:
-
您正在将整列与单个值进行比较
edata3['class']=='good' -
是的。还有一个名为 class 的列,它的值只有好或坏。所以在此基础上,我想将类列显示良好的单词添加到这个变量 good_words
-
你在用熊猫吗?
-
是的,使用熊猫
-
在
edata3发布预期的输出和样本数据
标签: python csv valueerror