编码csv文件时:ValueError:系列的真值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()

问题描述 投票:0回答:1

给出一个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 ...
python csv valueerror
1个回答
0
投票

good_words =''.join([edata3 [edata3 ['class'] =='good'] ['CleanedText']]]]

此方法有效。

© www.soinside.com 2019 - 2024. All rights reserved.