0

I am running the following code:

 def backwash (df):
    df.loc[0, 'backwash'] = np.NaN
     for i in range (3, len(df)-2):
         while (df.loc[i,'MF1 Permeate Flow (m3/min)']==0):
            if (df.loc[i-2:i+2, 'MF1 Trans-Membrane Pressure (kPa) (PDI3423)']>0):
                 df.loc[i,'backwash'] = 'BW'
                 break
            else:
                break
        else:
            pass
    return df

The problem is with df.loc [i-2:i+2, 'MF1 Trans-Membrane Pressure (kPa) (PDI3423)']. Hence I get the Value error (the truth value is ambiguous). Is there any other way to run this loop?

I essentially want to check the value on certain row based on the value of previous and following two rows.

mozway
  • 194,879
  • 13
  • 39
  • 75
Aimas
  • 79
  • 5
  • would be great to provide an example input and the matching expected output – mozway Sep 28 '21 at 07:59
  • 1
    You cannot compare a Series of booleans to a unique boolean, you need: `if all(df.loc[i-2:i+2, 'MF1 Trans-Membrane Pressure (kPa) (PDI3423)']>0)` to check if all values are True or `any` if only one True matters – mozway Sep 28 '21 at 08:02
  • ** got automatically while trying to bold it here. That's not the part of code. – Aimas Sep 28 '21 at 08:03
  • ok, you cannot format code, I fixed it – mozway Sep 28 '21 at 08:04

0 Answers0