<h4 dir="auto">Copy-pastable examples:</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
fileName = 'temp/df.h5'

#### Example 1

t = pd.DataFrame(data={'k':['A','B','C'],
                       'x':[ 1., 2., 3.]})
t.set_index(['k'], inplace=True)
t.sort_index(inplace=True)

t.to_hdf(fileName, 't', format='table')

t2 = pd.read_hdf(fileName, where='k==&quot;A&quot;'    ) # XXX: does not work
t2 = pd.read_hdf(fileName, where='k in [&quot;A&quot;]') # XXX: does not work
t2 = pd.read_hdf(fileName, where='k in {&quot;A&quot;}') # XXX: does not work

#### Example 2

t = pd.DataFrame(data={'k1':['A','B','C'],
                       'k2':[ 10, 20, 30],
                       'x' :[ 1., 2., 3.]})
t.set_index(['k1','k2'], inplace=True)
t.sort_index(inplace=True)

t.to_hdf(fileName, 't', format='table')

t2 = pd.read_hdf(fileName, where='k1==&quot;A&quot;'    ) # XXX: works
t2 = pd.read_hdf(fileName, where='k1 in [&quot;A&quot;]') # XXX: works
t2 = pd.read_hdf(fileName, where='k1 in {&quot;A&quot;}') # XXX: does not work
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-s1">fileName</span> <span class="pl-c1">=</span> <span class="pl-s">'temp/df.h5'</span>

<span class="pl-c">#### Example 1</span>

<span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">data</span><span class="pl-c1">=</span>{<span class="pl-s">'k'</span>:[<span class="pl-s">'A'</span>,<span class="pl-s">'B'</span>,<span class="pl-s">'C'</span>],
                       <span class="pl-s">'x'</span>:[ <span class="pl-c1">1.</span>, <span class="pl-c1">2.</span>, <span class="pl-c1">3.</span>]})
<span class="pl-s1">t</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'k'</span>], <span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-s1">t</span>.<span class="pl-en">sort_index</span>(<span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-s1">t</span>.<span class="pl-en">to_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s">'t'</span>, <span class="pl-s1">format</span><span class="pl-c1">=</span><span class="pl-s">'table'</span>)

<span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s1">where</span><span class="pl-c1">=</span><span class="pl-s">'k=="A"'</span>    ) <span class="pl-c"># XXX: does not work</span>
<span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s1">where</span><span class="pl-c1">=</span><span class="pl-s">'k in ["A"]'</span>) <span class="pl-c"># XXX: does not work</span>
<span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s1">where</span><span class="pl-c1">=</span><span class="pl-s">'k in {"A"}'</span>) <span class="pl-c"># XXX: does not work</span>

<span class="pl-c">#### Example 2</span>

<span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">data</span><span class="pl-c1">=</span>{<span class="pl-s">'k1'</span>:[<span class="pl-s">'A'</span>,<span class="pl-s">'B'</span>,<span class="pl-s">'C'</span>],
                       <span class="pl-s">'k2'</span>:[ <span class="pl-c1">10</span>, <span class="pl-c1">20</span>, <span class="pl-c1">30</span>],
                       <span class="pl-s">'x'</span> :[ <span class="pl-c1">1.</span>, <span class="pl-c1">2.</span>, <span class="pl-c1">3.</span>]})
<span class="pl-s1">t</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'k1'</span>,<span class="pl-s">'k2'</span>], <span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-s1">t</span>.<span class="pl-en">sort_index</span>(<span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-s1">t</span>.<span class="pl-en">to_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s">'t'</span>, <span class="pl-s1">format</span><span class="pl-c1">=</span><span class="pl-s">'table'</span>)

<span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s1">where</span><span class="pl-c1">=</span><span class="pl-s">'k1=="A"'</span>    ) <span class="pl-c"># XXX: works</span>
<span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s1">where</span><span class="pl-c1">=</span><span class="pl-s">'k1 in ["A"]'</span>) <span class="pl-c"># XXX: works</span>
<span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_hdf</span>(<span class="pl-s1">fileName</span>, <span class="pl-s1">where</span><span class="pl-c1">=</span><span class="pl-s">'k1 in {"A"}'</span>) <span class="pl-c"># XXX: does not work</span></pre></div>
<h4 dir="auto">Problem description</h4>
<ul dir="auto">
<li>'where' queries seem to completely fail if the DataFrame has single str index</li>
<li>'where' queries do not support sets, which are much more algorithmically efficient for searches than lists (in my use cases, I select routinely keys, which belong to sets with hundreds or thousands of elements)</li>
</ul>
<h4 dir="auto">Expected Output</h4>
<ul dir="auto">
<li>It would be great to support the single index case</li>
<li>It would be great to allow sets in 'where' queries</li>
</ul>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-693.17.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.utf-8
LANG: en_US.utf-8
LOCALE: en_US.UTF-8

pandas: 0.23.0
pytest: 3.3.2
pip: 10.0.1
setuptools: 39.0.1
Cython: 0.27.3
numpy: 1.14.3
scipy: 1.0.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-693.17.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.utf-8
LANG: en_US.utf-8
LOCALE: en_US.UTF-8

pandas: 0.23.0
pytest: 3.3.2
pip: 10.0.1
setuptools: 39.0.1
Cython: 0.27.3
numpy: 1.14.3
scipy: 1.0.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
</code></pre></div>
<p dir="auto">from <a href="http://stackoverflow.com/questions/27354281/query-term-is-not-valid-condition-none/27356827#27356827" rel="nofollow">SO</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: df = pd.DataFrame.from_dict({'A':[1,2],'B':[100,200], 'C':[42,11]})
In [2]: df_a = df.set_index('A')
In [3]: df_a
Out[3]: 
     B   C
A         
1  100  42
2  200  11

In [4]: store = pd.HDFStore('foo.h5','w')
In [5]: store.put('bar', df_a, format='table', data_columns=True)
In [7]: store.select('bar','index==1')"><pre class="notranslate"><code class="notranslate">In [1]: df = pd.DataFrame.from_dict({'A':[1,2],'B':[100,200], 'C':[42,11]})
In [2]: df_a = df.set_index('A')
In [3]: df_a
Out[3]: 
     B   C
A         
1  100  42
2  200  11

In [4]: store = pd.HDFStore('foo.h5','w')
In [5]: store.put('bar', df_a, format='table', data_columns=True)
In [7]: store.select('bar','index==1')
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="store.select('bar','A==1)"><pre class="notranslate"><code class="notranslate">store.select('bar','A==1)
</code></pre></div>
<p dir="auto">should work as well (obviously only for a named index)</p>