0

I need to add below functionality in my script

Below is the excel:

Name    Value1  Value2  PASS/FAIL

Name1     10     0       FAIL

Name2     20     5       PASS

Name3     30     0       FAIL

Name4     40     0       FAIL

Name5     50     0       FAIL

I need to search PASS string in 'PASS/FAIL' column. If 'PASS' string is present i need to move the Value1 to Value2 and Value1 column update as '0'.

Any help is appreciated.

Thanks in Advance.

anky
  • 74,114
  • 11
  • 41
  • 70
  • 1
    Use `mask= df['PASS/FAIL'] == 'PASS'`, `df['Value2'] = np.where(mask, df['Value1'], df['Value2'])` and `df['Value1'] = np.where(mask, 0, df['Value1'])` – Mohit Motwani Jul 07 '19 at 11:05
  • or you can create a 2D array like: `s=np.column_stack((np.where(m,0,df.Value1),df.Value1.values))` , then use `df[['Value1','Value2']]=df[['Value1','Value2']].mask(m,s)` @MohitMotwani found another way. :) – anky Jul 07 '19 at 11:17

1 Answers1

0

Check this part of code:

df['value2']=df['value1'] if df['PASS/FAIL']==PASS
df['value1'] = 0 if df['PASS/FAIL']==PASS