I'm trying to set a column based on the value of other columns in my dataframe, but i'm having a hard time with the syntax of this. I can best describe this with an example:
Say you have a dataframe: the columns "Computer", "IP", "IP2" "Signal", "Connected"
data = {'Computer':['cp1', 'cp2'], 'IP1':[51.20, 51.21], IP2:[52.20, 52.21], 'Signal':[IN, OUT]}
df = pd.DataFrame(data)
df[Connected]=np.nan
Here's what I've tried:
for i in df['Signal']:
if i =='IN':
df['Connected']= df['IP2']
else: df['Connected'] =df[IP1]
But this doesn't give me the correct output.
What I would like as an output is for every instance of 'IN' Connected takes the value of IP2 And for every instance of 'OUT' it takes the value of IP1
I hope this makes sense. Thank you