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 . Therefore, I want to get 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 used i to indicate the mileage on all lines of the frame. Pandas makes it easy to find rows containing null columns:
df[df.B == 0] and df[df.C == 0]
however, I have no idea how easy it is to perform the above conversion. I can think of various ineffective and inelegant methods ( for loops throughout the frame), but nothing simple.
Freddie witherden
source share