Home > Enterprise >  RETURN a value from other COLUMN based on the IF ELSE condition
RETURN a value from other COLUMN based on the IF ELSE condition

Time:10-20

DataoutHow can I use function based on IF ELSE condition to use following result?

Condition are based on 'Priority' columns and return values from 'Check' column to new Column Conditions: if Priority == CP 1 or CP 2: return values from 'Check' to Column 'Final' else: return: 'No' to Column 'Final' I tried and unable to return values from the column 'Check'

Data Input Expected data out

CodePudding user response:

you can implement if-else condition using np.where

import numpy as np

# check for conditions, Priority being CP1 or CP2
# when true return df['Check']
# else No
df['Final'] = np.where(df['Priority'].isin(['CP 1','CP 2']), df['Check'], 'No')

PS: if you post the data as a code or text, i would have been able to share the result

  • Related