0

I have a df structured as follows:

text sentiment
XXXXX yes
YYYYYY no

I'm trying to check the accuracy manually, according to this code ... however, I can't apply it to my DF. and I have the following error: ValueError: too many values to unpack (expected 2)

    for text, sentiment in df:
    classification = TextBlob(text).sentiment.polarity

if (classification <=0 and sentiment == "no"):
    Sum_classification +=1
elif (classification >=0 and sentiment =="yes"):
    Sum_classification +=1  

print("the Accuracy is ", Sum_classification/len(df))

So, I decided to transform this to the list using the following code, which makes the code run without error, but I don't have the expected result, once I get

the Accuracy is 0.0

list = list(zip(df_test['text'], df_test['sentiment']))
Tazz
  • 81
  • 9

2 Answers2

0

You can try to use the following to iterate through each row in your DataFrame:

for index, row in df.iterrows():

You can then access the sentiment text with

row.sentiment

So you would probably want to do something like this:

for index, row in df.iterrows():
    sentiment = row.sentiment
    classification = TextBlob(sentiment).polarity

dlever
  • 21
  • 5
0

lazy work:

# create a int column
df['int sentiment'] = df['sentiment'].apply(lambda x: 1 if x == 'yes' else 0)

avg = sum(df['int sentiment'])/len(df['int sentiment'])

print(f'Average is {avg}')

Now you won't need to run the code and load all data frame again for each interaction, you will work with only one column to build your metrics.

hbrandao
  • 3
  • 1
  • 4