For Example:
I have columns A and B, and I need to do a quality check to make sure that Column B is Null every time Column A is 'Cash'. I don't wan't it to output every row, I just want to know (True/False) if Column B is Null for every time Column A is 'Cash'.
My current (not working) code:
mylist = []
while [df['A'] == 'Cash'] and [df['B'] is None]:
mylist.append('Pass')
else:
mylist.append('Fail')
if 'Fail' in mylist:
print 'Column A Pass'
else:
print 'Column A Pass'
if Column B is Null for every time Column A is 'Cash'?
aCash = df.A == "Cash"
bNull = df.B.isnull()
aCash.sum() == (aCash & bNull).sum()
aCash itself it means for all rows where A is Cash, B is NULL. test equality of conditions
d1.A.eq('Cash').eq(d1.B.isnull()).all()
demo
d1 = pd.DataFrame(dict(
A=['a', 'b', 'Cash', 'c', 'Cash', 'd'],
B=[1, 1, None, 1, None, 1],
C=[1, None, 1, 1, 1, 1]
))
print(d1)
A B C
0 a 1.0 1.0
1 b 1.0 NaN
2 Cash NaN 1.0
3 c 1.0 1.0
4 Cash NaN 1.0
5 d 1.0 1.0
d1.A.eq('Cash').eq(d1.B.isnull()).all()
True
d1.A.eq('Cash').eq(d1.C.isnull()).all()
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With