or condition in pandas
df1 = df[(df.a != -1) & (df.b != -1)]
or condition in pandas
df1 = df[(df.a != -1) & (df.b != -1)]
pandas where
In [20]: df
Out[20]:
A B C
0 1 2 1
1 2 3 0
2 3 4 0
3 4 5 1
# Note that df.C is a mask
# Note that this is np.where, not df.where. That is different.
In [21]: df['D'] = np.where(df.C, df.A, df.B)
In [22]: df
Out[22]:
A B C D
0 1 2 1 1
1 2 3 0 3
2 3 4 0 4
3 4 5 1 4
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us