<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
import numpy as np
idx0 = range(2)
idx1 = np.repeat(range(2), 2)

midx = pd.MultiIndex(
    levels=[idx0, idx1],
    labels=[
        np.repeat(range(len(idx0)), len(idx1)),
        np.tile(range(len(idx1)), len(idx0))
    ],
    names=['idx0', 'idx1']
)

df = pd.DataFrame(
    [
        [i**2/float(j), 'example{}'.format(i), i**3/float(j)]
        for j in range(1, len(idx0) + 1)
        for i in range(1, len(idx1) + 1)
    ],
    columns=['col0', 'col1', 'col2'],
    index=midx
)

example = df.loc[[(0, 1)]]"><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-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">idx0</span> <span class="pl-c1">=</span> <span class="pl-en">range</span>(<span class="pl-c1">2</span>)
<span class="pl-s1">idx1</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">repeat</span>(<span class="pl-en">range</span>(<span class="pl-c1">2</span>), <span class="pl-c1">2</span>)

<span class="pl-s1">midx</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>(
    <span class="pl-s1">levels</span><span class="pl-c1">=</span>[<span class="pl-s1">idx0</span>, <span class="pl-s1">idx1</span>],
    <span class="pl-s1">labels</span><span class="pl-c1">=</span>[
        <span class="pl-s1">np</span>.<span class="pl-en">repeat</span>(<span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">idx0</span>)), <span class="pl-en">len</span>(<span class="pl-s1">idx1</span>)),
        <span class="pl-s1">np</span>.<span class="pl-en">tile</span>(<span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">idx1</span>)), <span class="pl-en">len</span>(<span class="pl-s1">idx0</span>))
    ],
    <span class="pl-s1">names</span><span class="pl-c1">=</span>[<span class="pl-s">'idx0'</span>, <span class="pl-s">'idx1'</span>]
)

<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(
    [
        [<span class="pl-s1">i</span><span class="pl-c1">**</span><span class="pl-c1">2</span><span class="pl-c1">/</span><span class="pl-en">float</span>(<span class="pl-s1">j</span>), <span class="pl-s">'example{}'</span>.<span class="pl-en">format</span>(<span class="pl-s1">i</span>), <span class="pl-s1">i</span><span class="pl-c1">**</span><span class="pl-c1">3</span><span class="pl-c1">/</span><span class="pl-en">float</span>(<span class="pl-s1">j</span>)]
        <span class="pl-k">for</span> <span class="pl-s1">j</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">1</span>, <span class="pl-en">len</span>(<span class="pl-s1">idx0</span>) <span class="pl-c1">+</span> <span class="pl-c1">1</span>)
        <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">1</span>, <span class="pl-en">len</span>(<span class="pl-s1">idx1</span>) <span class="pl-c1">+</span> <span class="pl-c1">1</span>)
    ],
    <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'col0'</span>, <span class="pl-s">'col1'</span>, <span class="pl-s">'col2'</span>],
    <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">midx</span>
)

<span class="pl-s1">example</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[[(<span class="pl-c1">0</span>, <span class="pl-c1">1</span>)]]</pre></div>
<p dir="auto">For display</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [13]: example
Out[13]:
           col0      col1  col2
idx0 idx1
0    1     16.0  example4  64.0"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">13</span>]: <span class="pl-s1">example</span>
<span class="pl-v">Out</span>[<span class="pl-c1">13</span>]:
           <span class="pl-s1">col0</span>      <span class="pl-s1">col1</span>  <span class="pl-s1">col2</span>
<span class="pl-s1">idx0</span> <span class="pl-s1">idx1</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>     <span class="pl-c1">16.0</span>  <span class="pl-s1">example4</span>  <span class="pl-c1">64.0</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Taken from this StackOverflow post:</p>
<ul dir="auto">
<li><a href="https://stackoverflow.com/q/46098097/4013571" rel="nofollow">https://stackoverflow.com/q/46098097/4013571</a></li>
</ul>
<p dir="auto">Given the following dataframe</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="           col0      col1  col2
idx0 idx1
0    0      1.0  example1   1.0
     0      4.0  example2   8.0
     1      9.0  example3  27.0
     1     16.0  example4  64.0
1    0      0.5  example1   0.5
     0      2.0  example2   4.0
     1      4.5  example3  13.5
     1      8.0  example4  32.0"><pre class="notranslate">           <span class="pl-s1">col0</span>      <span class="pl-s1">col1</span>  <span class="pl-s1">col2</span>
<span class="pl-s1">idx0</span> <span class="pl-s1">idx1</span>
<span class="pl-c1">0</span>    <span class="pl-c1">0</span>      <span class="pl-c1">1.0</span>  <span class="pl-s1">example1</span>   <span class="pl-c1">1.0</span>
     <span class="pl-c1">0</span>      <span class="pl-c1">4.0</span>  <span class="pl-s1">example2</span>   <span class="pl-c1">8.0</span>
     <span class="pl-c1">1</span>      <span class="pl-c1">9.0</span>  <span class="pl-s1">example3</span>  <span class="pl-c1">27.0</span>
     <span class="pl-c1">1</span>     <span class="pl-c1">16.0</span>  <span class="pl-s1">example4</span>  <span class="pl-c1">64.0</span>
<span class="pl-c1">1</span>    <span class="pl-c1">0</span>      <span class="pl-c1">0.5</span>  <span class="pl-s1">example1</span>   <span class="pl-c1">0.5</span>
     <span class="pl-c1">0</span>      <span class="pl-c1">2.0</span>  <span class="pl-s1">example2</span>   <span class="pl-c1">4.0</span>
     <span class="pl-c1">1</span>      <span class="pl-c1">4.5</span>  <span class="pl-s1">example3</span>  <span class="pl-c1">13.5</span>
     <span class="pl-c1">1</span>      <span class="pl-c1">8.0</span>  <span class="pl-s1">example4</span>  <span class="pl-c1">32.0</span></pre></div>
<p dir="auto">the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.xs.html" rel="nofollow"><code class="notranslate">.xs</code></a> operation will select</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [121]: df.xs((0,1), level=[0,1])
Out[121]:
           col0      col1  col2
idx0 idx1
0    1      9.0  example3  27.0
     1     16.0  example4  64.0"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">121</span>]: <span class="pl-s1">df</span>.<span class="pl-en">xs</span>((<span class="pl-c1">0</span>,<span class="pl-c1">1</span>), <span class="pl-s1">level</span><span class="pl-c1">=</span>[<span class="pl-c1">0</span>,<span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">121</span>]:
           <span class="pl-s1">col0</span>      <span class="pl-s1">col1</span>  <span class="pl-s1">col2</span>
<span class="pl-s1">idx0</span> <span class="pl-s1">idx1</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>      <span class="pl-c1">9.0</span>  <span class="pl-s1">example3</span>  <span class="pl-c1">27.0</span>
     <span class="pl-c1">1</span>     <span class="pl-c1">16.0</span>  <span class="pl-s1">example4</span>  <span class="pl-c1">64.0</span></pre></div>
<p dir="auto">whilst the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html" rel="nofollow"><code class="notranslate">.loc</code></a> operation will select</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [125]: df.loc[[(0,1)]]
Out[125]:
           col0      col1  col2
idx0 idx1
0    1     16.0  example4  64.0"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">125</span>]: <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[[(<span class="pl-c1">0</span>,<span class="pl-c1">1</span>)]]
<span class="pl-v">Out</span>[<span class="pl-c1">125</span>]:
           <span class="pl-s1">col0</span>      <span class="pl-s1">col1</span>  <span class="pl-s1">col2</span>
<span class="pl-s1">idx0</span> <span class="pl-s1">idx1</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>     <span class="pl-c1">16.0</span>  <span class="pl-s1">example4</span>  <span class="pl-c1">64.0</span></pre></div>
<p dir="auto">This is highlighted even further by the following</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [149]: df.loc[pd.IndexSlice[:, 1], :]
Out[149]:
           col0      col1  col2
idx0 idx1
0    1      9.0  example3  27.0
     1     16.0  example4  64.0

In [150]: df.loc[pd.IndexSlice[0, 1], :]
Out[150]:
col0          16
col1    example4
col2          64
Name: (0, 1), dtype: object"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">149</span>]: <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[<span class="pl-s1">pd</span>.<span class="pl-v">IndexSlice</span>[:, <span class="pl-c1">1</span>], :]
<span class="pl-v">Out</span>[<span class="pl-c1">149</span>]:
           <span class="pl-s1">col0</span>      <span class="pl-s1">col1</span>  <span class="pl-s1">col2</span>
<span class="pl-s1">idx0</span> <span class="pl-s1">idx1</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>      <span class="pl-c1">9.0</span>  <span class="pl-s1">example3</span>  <span class="pl-c1">27.0</span>
     <span class="pl-c1">1</span>     <span class="pl-c1">16.0</span>  <span class="pl-s1">example4</span>  <span class="pl-c1">64.0</span>

<span class="pl-v">In</span> [<span class="pl-c1">150</span>]: <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[<span class="pl-s1">pd</span>.<span class="pl-v">IndexSlice</span>[<span class="pl-c1">0</span>, <span class="pl-c1">1</span>], :]
<span class="pl-v">Out</span>[<span class="pl-c1">150</span>]:
<span class="pl-s1">col0</span>          <span class="pl-c1">16</span>
<span class="pl-s1">col1</span>    <span class="pl-s1">example4</span>
<span class="pl-s1">col2</span>          <span class="pl-c1">64</span>
<span class="pl-v">Name</span>: (<span class="pl-c1">0</span>, <span class="pl-c1">1</span>), <span class="pl-s1">dtype</span>: <span class="pl-s1">object</span></pre></div>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Note that this only works for this minimal example because there is only one label in level 0 index axis</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [8]: df.loc[pd.IndexSlice[:, 1], :]
Out[8]:
           col0      col1  col2
idx0 idx1
0    1      9.0  example3  27.0
     1     16.0  example4  64.0"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">8</span>]: <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[<span class="pl-s1">pd</span>.<span class="pl-v">IndexSlice</span>[:, <span class="pl-c1">1</span>], :]
<span class="pl-v">Out</span>[<span class="pl-c1">8</span>]:
           <span class="pl-s1">col0</span>      <span class="pl-s1">col1</span>  <span class="pl-s1">col2</span>
<span class="pl-s1">idx0</span> <span class="pl-s1">idx1</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>      <span class="pl-c1">9.0</span>  <span class="pl-s1">example3</span>  <span class="pl-c1">27.0</span>
     <span class="pl-c1">1</span>     <span class="pl-c1">16.0</span>  <span class="pl-s1">example4</span>  <span class="pl-c1">64.0</span></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 2.7.13.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 7<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 79 Stepping 1, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.20.3<br>
pytest: 3.0.7<br>
pip: 9.0.1<br>
setuptools: 36.2.7<br>
Cython: 0.25.2<br>
numpy: 1.13.1<br>
scipy: 0.19.0<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: 1.5.6<br>
patsy: 0.4.1<br>
dateutil: 2.6.1<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.2.2<br>
numexpr: 2.6.2<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: 2.4.7<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.3<br>
bs4: 4.6.0<br>
html5lib: 0.999<br>
sqlalchemy: 1.1.9<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: 0.5.0</p>
</details>
<p dir="auto">I have an odd issue where if I specify the axis in concat it throws the following error:</p>
<p dir="auto">InvalidIndexError: Reindexing only valid with uniquely valued Index objects</p>
<p dir="auto">Pandas version: 0.16.0<br>
OS: Ubuntu 14.04 LTS x64</p>
<p dir="auto">Here's the pickle of the data structure causing this (it's rather large, ~60 megs, but it's my real use case which caused this error)</p>
<p dir="auto"><a href="https://www.dropbox.com/s/02dn99dbi6p14um/pandas_error.pickle?dl=0" rel="nofollow">https://www.dropbox.com/s/02dn99dbi6p14um/pandas_error.pickle?dl=0</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import pickle
import pandas as pd
l = pickle.load(open('pandas_error.pickle'))
scan_query = '(index &gt;= 624.306193 &amp; index &lt;= 624.326171) | (index &gt;= 624.807981 &amp; index &lt;= 624.826795) | (index &gt;= 625.309633 &amp; index &lt;= 625.32635) | (index &gt;= 628.315655 &amp; index &lt;= 628.331508) | (index &gt;= 628.815043 &amp; index &lt;= 628.83164)'
# works
pd.concat([i.dropna().to_frame().query(scan_query) for i in l])
# breaks
#pd.concat([i.dropna().to_frame().query(scan_query) for i in l], axis=1)"><pre class="notranslate"><code class="notranslate">import pickle
import pandas as pd
l = pickle.load(open('pandas_error.pickle'))
scan_query = '(index &gt;= 624.306193 &amp; index &lt;= 624.326171) | (index &gt;= 624.807981 &amp; index &lt;= 624.826795) | (index &gt;= 625.309633 &amp; index &lt;= 625.32635) | (index &gt;= 628.315655 &amp; index &lt;= 628.331508) | (index &gt;= 628.815043 &amp; index &lt;= 628.83164)'
# works
pd.concat([i.dropna().to_frame().query(scan_query) for i in l])
# breaks
#pd.concat([i.dropna().to_frame().query(scan_query) for i in l], axis=1)
</code></pre></div>