mercredi 15 juin 2016

Trouble evaluating response to .loc in pandas

I have code as shown below. What I want to do is to look at the values in cells which I've accessed using .loc and test these for three conditions using an If statement.

The message that I get back is

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

I think that pandas returns a series even if there is only one item which is why this happens. But when I tried using any() I got the message

AttributeError: 'str' object has no attribute 'any'

So I'm stuck. Any help would be very much appreciated.

for my_index, row in PPI_data.iterrows():
        if PPI_data.loc[my_index,"Incident counter"]<3 and PPI_data.loc[my_index,"Risk Level"]=="Standard" and PPI_data.loc[my_index,"Crime number"]=='Not crime':
            PPI_data.set_value(my_index, 'Eligability to visit', "Eligable")
        else:
            PPI_data.set_value(my_index, 'Eligability to visit', "Not eligable")

Aucun commentaire:

Enregistrer un commentaire