I have a dataframe like that contains of 5 columns , I want to update one column based on the other 4 columns, the dataframe looks like that
from via to x y
3 2 13 in out
3 2 15 in out
3 2 21 in out
13 2 3
15 2 13
21 2 13
1 12 2
1 12 2
1 12 22
2 12 1 in
2 12 22 in out
22 12 2
the idea is to fill the column X depending on values on the other four columns, the sequence should be like that: i have to check if x and y have values , if yes, then i have to use the corresponding values of (from ,via) and compare it in all rows with the values of (to, via) if they are the same, so i have to assign the value of Y which is correponding to (from, via) to the column X at the row which has equal values of ( to, via) so at this example, I can see that (from=3, Via=2 has x and y values, so i will take the value of (from=3, Via=2) and compare it with the values of (to, via) in all rows, then I can assign the value of (y=out) at the rows which has (to=3, via=10)
the final result should be like that:
from via to x y
3 2 13 in out
3 2 15 in out
3 2 21 in
13 2 3 out
15 2 13 out
21 2 13
1 12 2 out
1 12 2 out
1 12 22 out
2 12 1 in
2 12 22 in out
22 12 2 out
how can i do that in pandas dataframe?