def apply_filters ( df , filters ) : idx = pd . Series ( [ True ] * df . shape [ 0 ] ) for k , v in list ( filters . items ( ) ) : if k not in df . columns : continue idx &= ( df [ k ] == v ) return df . loc [ idx ]
python filter data in a data frame
Basic filtering for a dataframe .
def apply_filters(df, filters):
        """Basic filtering for a dataframe."""
        idx = pd.Series([True]*df.shape[0])
        for k, v in list(filters.items()):
            if k not in df.columns:
                continue
            idx &= (df[k] == v)

        return df.loc[idx]