I have a Pandas DataFrame with four columns, A, B, C, D. It turns out that, sometimes, the values of B and C can be 0. I therefore wish to obtain the following:
B[i] = B[i] if B[i] else min(A[i], D[i])
C[i] = C[i] if C[i] else max(A[i], D[i])
where I have used i to indicate a run over all rows of the frame. With Pandas it is easy to find the rows which contain zero columns:
df[df.B == 0] and df[df.C == 0]
however I have no idea how to easily perform the above transformation. I can think of various inefficient and inelegant methods (for loops over the entire frame) but nothing simple.