cenpy.products._Product.filter_variables

_Product.filter_variables(self, pattern=None, by=None, engine='re')[source]

Grabs columns that match a particular search pattern.

Parameters
patternstr

a search pattern to match

bystr

a column in the APIConnection.variables to conduct the search within

engine{‘re’, ‘fnmatch’, callable}

backend string matching module to use, or a function of the form match(candidate, pattern). (default: ‘re’)

withinpandas.DataFrame

the variables over which to search.

Notes

Only regex and fnmatch will be supported modules. Note that, while regex is the default, the python regular expressions module has some strange behavior if you’re used to VIM or Perl-like regex. It may be easier to use fnmatch if regex is not providing the results you expect.

If you want, you can also pass an engine that is a function. If so, this needs to be a function that has a signature like:

fn(candidate, pattern)

and return True or False if the candidate matches the pattern. So, for instance, you can use any string processing function:

>>> cxn.varslike('_100M', engine = lambda c,p: c.endswith(p)

which may also be expressed as a regexp:

>>> cxn.varslike('_100M$', engine='re')

or an fnmatch pattern:

>>> cxn.varslike('*_100M', engine='fnmatch')