I need to calculate some probabilities given certain conditions, so I'm using a function to get the rows that contain givens values, for example:
df:
col1 col2 col3
A B C
H B C
A B
A H C
This is the function
def existence(x):
return df[df.isin([x]).any(1)]
So if I do:
in:
existence('A')
out:
col1 col2 col3
A B C
A B
A H C
I need to generalize the function, so that I can give it more than one parameter and do the following:
existence(x, y):
return df[df.isin([x]).any(1) & df.isin([y]).any(1)]
or generalized
existence(x1, x2,..., xn):
return df[df.isin([x1]).any(1) & df.isin([x2]).any(1) & ... & df.isin([xn]).any(1)]
I think args can't help me since I can't merge operations with the operator &
thank you in advance estimates
def existence(x): return df[df.isin(x).any(1)], thenexistence(['A'])orexistence(['A','B'])