lundi 5 novembre 2018

Checking when more than one dataframe column has specific values in Python

I have data that is in the form that looks like:

Shop              Date             Produced         Lost        Output     Signal
Cornerstop        01-01-2010          0              1            9          1
Cornerstop        01-01-2010          11             1            11         0
Cornerstop        01-01-2010          0              0            0          2
Cornerstop        01-01-2010          1              0            0          2
Cornerstop        01-01-2010          5              7            0          2
.
.
.
.

The data SHOULD have values for 'Lost' and 'Output' that are 0 when 'Produced' is 0 but that's not the case. I need a way to find out when this isn't the case (when Produced is 0 but any of Lost, Output, or Signal are not 0).

Making a counter that counts the times this is true or not is what I used to see the number like:

counter = 0

for index, row in data.iterrows():
    if row['Produced'] and row['Lost'] != 0:
        counter += 1
    else:
        continue

I'd like to see exactly which rows in the dataframe these are (it's a large set) and this is hardly very efficient to search by each row.

Is there a better way I can do this?

Aucun commentaire:

Enregistrer un commentaire