mercredi 24 avril 2019

How to compare string value by index and column and apply AND OR logic within dataframe?

I have a dataframe that looks like this:

   col1
0  ofcourse
1  I love the service

The dataframe could also have this value for row 1:

   col1
0  ofcourse
1  I hate the service

I want to compare the value of the strings by row and column and be able to check for one of two values in row1.

I want to create this logic:

if df.col1.loc[[0]] =='Of course!' and (df.col1.loc[[1]]=='I love the service' or df.col1.loc[[1]]=='I hate the service'):
    print('good')

When I run the logic above I get error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire