def select_if ( df , fun ) : def _filter_f ( col ) : try : return fun ( df [ col ] ) except : return False cols = list ( filter ( _filter_f , df . columns ) ) return df [ cols ]
select specifi coluns in a df in python
Selects columns where fun ( ction ) is true Args : fun : a function that will be applied to columns
def select_if(df, fun):
    """Selects columns where fun(ction) is true
    Args:
        fun: a function that will be applied to columns
    """

    def _filter_f(col):
        try:
            return fun(df[col])
        except:
            return False

    cols = list(filter(_filter_f, df.columns))
    return df[cols]