Filter dataframe to include specified columns, retaining any Intensity columns.
192016
def filter_select_columns_intensity(df, prefix, columns):
    
    # Note: I use %s.+ (not %s.*) so it forces a match with the prefix string, ONLY if it is followed by something.
    return df.filter(regex='^(%s.+|%s)$' % (prefix, '|'.join(columns)) )
1152498
def filter_by_cols(self, cols, ID=None):
        
        rows = to_list(cols)
        fil = lambda x: x in rows
        applyto = {k: self._positions[k][1] for k in self.keys()}
        if ID is None:
            ID = self.ID + '.filtered_by_cols'
        return self.filter(fil, applyto=applyto, ID=ID)
929147
def none_missing(df, columns=None):
    
    if columns is None:
        columns = df.columns
    assert not df[columns].isnull().any().any()
    return df
1082123
def get_filters(cls, raw_filters, num_cols, columns_dict):  # noqa
        """"""
        filters = None
        for flt in raw_filters:
            col = flt.get('col')
            op = flt.get('op')
            eq = flt.get('val')
            if (
                    not col or
                    not op or
                    (eq is None and op not in ('IS NULL', 'IS NOT NULL'))):
                continue

            # Check if this dimension uses an extraction function
            # If so, create the appropriate pydruid extraction object
            column_def = columns_dict.get(col)
            dim_spec = column_def.dimension_spec if column_def else None
            extraction_fn = None
            if dim_spec and 'extractionFn' in dim_spec:
                (col, extraction_fn) = DruidDatasource._create_extraction_fn(dim_spec)

            cond = None
            is_numeric_col = col in num_cols
            is_list_target = op in ('in', 'not in')
            eq = cls.filter_values_handler(
                eq, is_list_target=is_list_target,
                target_column_is_numeric=is_numeric_col)

            # For these two ops, could have used Dimension,
            # but it doesn't support extraction functions
            if op == '==':
                cond = Filter(dimension=col, value=eq, extraction_function=extraction_fn)
            elif op == '!=':
                cond = ~Filter(dimension=col, value=eq, extraction_function=extraction_fn)
            elif op in ('in', 'not in'):
                fields = []
                # ignore the filter if it has no value
                if not len(eq):
                    continue
                # if it uses an extraction fn, use the "in" operator
                # as Dimension isn't supported
                elif extraction_fn is not None:
                    cond = Filter(
                        dimension=col,
                        values=eq,
                        type='in',
                        extraction_function=extraction_fn,
                    )
                elif len(eq) == 1:
                    cond = Dimension(col) == eq[0]
                else:
                    for s in eq:
                        fields.append(Dimension(col) == s)
                    cond = Filter(type='or', fields=fields)
                if op == 'not in':
                    cond = ~cond
            elif op == 'regex':
                cond = Filter(
                    extraction_function=extraction_fn,
                    type='regex',
                    pattern=eq,
                    dimension=col,
                )

            # For the ops below, could have used pydruid's Bound,
            # but it doesn't support extraction functions
            elif op == '>=':
                cond = Filter(
                    type='bound',
                    extraction_function=extraction_fn,
                    dimension=col,
                    lowerStrict=False,
                    upperStrict=False,
                    lower=eq,
                    upper=None,
                    alphaNumeric=is_numeric_col,
                )
            elif op == '<=':
                cond = Filter(
                    type='bound',
                    extraction_function=extraction_fn,
                    dimension=col,
                    lowerStrict=False,
                    upperStrict=False,
                    lower=None,
                    upper=eq,
                    alphaNumeric=is_numeric_col,
                )
            elif op == '>':
                cond = Filter(
                    type='bound',
                    extraction_function=extraction_fn,
                    lowerStrict=True,
                    upperStrict=False,
                    dimension=col,
                    lower=eq,
                    upper=None,
                    alphaNumeric=is_numeric_col,
                )
            elif op == '<':
                cond = Filter(
                    type='bound',
                    extraction_function=extraction_fn,
                    upperStrict=True,
                    lowerStrict=False,
                    dimension=col,
                    lower=None,
                    upper=eq,
                    alphaNumeric=is_numeric_col,
                )
            elif op == 'IS NULL':
                cond = Dimension(col) == None  # NOQA
            elif op == 'IS NOT NULL':
                cond = Dimension(col) != None  # NOQA

            if filters:
                filters = Filter(type='and', fields=[
                    cond,
                    filters,
                ])
            else:
                filters = cond

        return filters
268170
def normalize_column_names(df):
    
    """
    columns = df.columns if hasattr(df, 'columns') else df
    columns = [c.lower().replace(' ', '_') for c in columns]
    return columns
401961
def has_index(self, columns):
        """"""
        if not self.exists:
            return False
        columns = set([normalize_column_name(c) for c in columns])
        if columns in self._indexes:
            return True
        for column in columns:
            if not self.has_column(column):
                return False
        indexes = self.db.inspect.get_indexes(self.name, schema=self.db.schema)
        for index in indexes:
            if columns == set(index.get('column_names', [])):
                self._indexes.append(columns)
                return True
        return False
474933
async def filter(self, request):
        """"""
        collection = self.collection
        self.filter_form.process(request.query)
        data = self.filter_form.data
        self.filter_form.active = any(o and o is not DEFAULT for o in data.values())
        for flt in self.columns_filters:
            try:
                collection = flt.apply(collection, data)
            # Invalid filter value
            except ValueError:
                continue
        return collection
100663
def filter_N_top(self, inst_rc, N_top, rank_type='sum'):
    '''
    
    '''
    inst_df = self.dat_to_df()

    inst_df = run_filter.filter_N_top(inst_rc, inst_df, N_top, rank_type)

    self.df_to_dat(inst_df)
152598
def process_axes(self, obj, columns=None):
        

        # make a copy to avoid side effects
        if columns is not None:
            columns = list(columns)

        # make sure to include levels if we have them
        if columns is not None and self.is_multi_index:
            for n in self.levels:
                if n not in columns:
                    columns.insert(0, n)

        # reorder by any non_index_axes & limit to the select columns
        for axis, labels in self.non_index_axes:
            obj = _reindex_axis(obj, axis, labels, columns)

        # apply the selection filters (but keep in the same order)
        if self.selection.filter is not None:
            for field, op, filt in self.selection.filter.format():

                def process_filter(field, filt):

                    for axis_name in obj._AXIS_NAMES.values():
                        axis_number = obj._get_axis_number(axis_name)
                        axis_values = obj._get_axis(axis_name)

                        # see if the field is the name of an axis
                        if field == axis_name:

                            # if we have a multi-index, then need to include
                            # the levels
                            if self.is_multi_index:
                                filt = filt.union(Index(self.levels))

                            takers = op(axis_values, filt)
                            return obj.loc._getitem_axis(takers,
                                                         axis=axis_number)

                        # this might be the name of a file IN an axis
                        elif field in axis_values:

                            # we need to filter on this dimension
                            values = ensure_index(getattr(obj, field).values)
                            filt = ensure_index(filt)

                            # hack until we support reversed dim flags
                            if isinstance(obj, DataFrame):
                                axis_number = 1 - axis_number
                            takers = op(values, filt)
                            return obj.loc._getitem_axis(takers,
                                                         axis=axis_number)

                    raise ValueError("cannot find the field [{field}] for "
                                     "filtering!".format(field=field))

                obj = process_filter(field, filt)

        return obj
1031091
def exclude(self, col: str, val):
        
        try:
            self.df = self.df[self.df[col] != val]
        except Exception as e:
            self.err(e, "Can not exclude rows based on value " + str(val))
1006089
def filter_set(input, **params):
    
    PARAM_WHERE = 'where'

    return Converter.df2list(pd.DataFrame.from_records(input).query(params.get(PARAM_WHERE)))
1061403
def filter_sum(self, inst_rc, threshold, take_abs=True):
    '''
    
    '''
    inst_df = self.dat_to_df()
    if inst_rc == 'row':
      inst_df = run_filter.df_filter_row_sum(inst_df, threshold, take_abs)
    elif inst_rc == 'col':
      inst_df = run_filter.df_filter_col_sum(inst_df, threshold, take_abs)
    self.df_to_dat(inst_df)
274485
def apply(self, df):
        """"""

        if self.subset:
            if _axis_is_rows(self.axis):
                df = df[self.subset]
            if _axis_is_cols(self.axis):
                df = df.loc[self.subset]

        result = df.agg(self.func, axis=self.axis, *self.args, **self.kwargs)
        result.name = self.title
        return result
1113284
function columnIndexing(selector, colNames, dtypes) {
  if (isUndefined(selector) || selector === null) {
    return null;
  }

  // Handle boolean case if applicable
  var maxLen = colNames.size();
  var boolIdxResult = attemptBoolIndexing(selector, maxLen);
  if (!isUndefined(boolIdxResult)) {
    return boolIdxResult;
  }

  // Handle integer index / col name lookup hybrid
  var opts = resolverOpts(RESOLVE_MODE.COL, maxLen,
    colNames._getIndex(), dtypes);
  return resolveSelector(selector, opts);
}
426787
def dataframe(df, **kwargs):
    
    table(df.values, list(df.columns), **kwargs)
45359
function  collectFilterColumns(dftTable, filter, col)  {
	var  isLogical = false;
	if (filter.op === 'AND' || filter.op === 'and' || filter.op === 'OR' || filter.op === 'or')  {
		filter.op = filter.op.toLowerCase();
		isLogical = true;
	}

	if (isLogical)  {
		filter.filters.forEach(function(f) {
			collectFilterColumns(dftTable, f, col);
		});
	}
	else  {
		var  colName = filter.field || filter.name,
			 fc = {tbName: dftTable, col: colName, orig: colName},
			 idx = colName.indexOf('.');

		if (idx > 0)  {
			fc.tbName = colName.substring(0, idx);
			fc.col = colName.substring(idx+1);
		}

		if (_.findIndex(col, fc) < 0)
			col.push(fc);
	}
}
1066080
def csv_column_cleaner(rows):
    

    # check columns if there was empty columns
    result = [[] for x in range(0, len(rows))]
    for i_index in range(0, len(rows[0])):

        partial_values = []

        for x_row in rows:
            partial_values.append(
                x_row[i_index] if len(x_row) > i_index else '')

        colum_rows = exclude_empty_values(partial_values)

        if len(colum_rows) > len(rows) / 5:  # adjust this value
            for index in range(0, len(rows)):
                result[index].append(
                    rows[index][i_index] if len(rows[index]) > i_index else '')
    return result