codeKiller
codeKiller

Reputation: 5748

complex query in PyTables using table.where

How can I do sokmething like that: (if possible)

options = {'topLimit': 22.3, 'downLimit': 9}

for row in tab.where('value < options['topLimit']'):
    #whatever
    ...
    ...

Can we put something like options['topLimit'] or something similar inside the where condition??

If not, how can it be done?

P.D: Note that this is a very simple example....I know the solution for this case is:

for row in tab.where('value < 22.3'):

I am thinking about much more complex situations.

Upvotes: 1

Views: 489

Answers (1)

Anthony Scopatz
Anthony Scopatz

Reputation: 3637

Pass options in as the condvars argument to where:

options = {'topLimit': 22.3, 'downLimit': 9}

for row in tab.where('value < topLimit', options):
    #whatever

See the documentation for more details [1].

  1. http://pytables.github.io/usersguide/libref/structured_storage.html?highlight=where#tables.Table.where

Upvotes: 2

Related Questions