psweep.psweep.df_filter_conds#
- psweep.psweep.df_filter_conds(df, conds, op='and')[source]#
Filter DataFrame using bool arrays/Series/DataFrames in conds.
Fuse all bool sequences in conds using op. For instance, if
op="and"
, then we logical-and them, which is equal to>>> df[conds[0] & conds[1] & conds[2] & ...]
but conds can be programmatically generated while the expression above would need to be changed by hand if conds changes.
- Parameters:
df (
DataFrame
) – DataFrameconds (
Sequence
[Sequence
[bool
]]) – Sequence of bool masks, each of length len(df).op (
str
) – Bool operator, used asnumpy.logical_{op}
, e.g. “and”, “or”, “xor”.
- Return type:
DataFrame
- Returns:
DataFrame
Examples
>>> df=pd.DataFrame({'a': arange(10), 'b': arange(10)+4}) >>> c1=df.a > 3 >>> c2=df.b < 9 >>> c3=df.a % 2 == 0 >>> df[c1 & c2 & c3] a b 4 4 8 >>> ps.df_filter_conds(df, [c1, c2, c3]) a b 4 4 8