<p dir="auto">I am trying to concatenating two Panels with duplicate <code class="notranslate">Items</code> (but different <code class="notranslate">major_axes</code>) together, without actually having to duplicate items... Did some searching but couldn't find much on SO.</p>
<p dir="auto">Unfortunately I cannot upload pics to github at the moment.. <strong>But screens are attached <a href="http://stackoverflow.com/questions/34652835/pandas-how-to-concatenate-two-panels-without-duplicating-items-axis-i-e-colum" rel="nofollow">here</a>.</strong></p>
<p dir="auto">To illustrate what I mean:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# create data
import pandas as pd
df1 = pd.DataFrame({'A' : [1, 2, 3], 'B' : [2, 5, 6]}, index={0, 1, 2})
df2 = pd.DataFrame({'A' : [1, 2, 3], 'B' : [2, 5, 6]}, index={3, 4, 5})
df3 = pd.DataFrame({'A' : [5, 2, 3], 'B' : [2, 5, 6]}, index={6, 7, 8})
df4 = pd.DataFrame({'A' : [6, 2, 3], 'B' : [2, 5, 6]}, index={9, 10, 11})

pan1 = pd.Panel({'X' : df1, 'Y': df2})
pan2 = pd.Panel({'X' : df3, 'Y': df4})

# concat these two panels above
pan3 = pd.concat([pan1, pan2])

pan3
Output:
&lt;class 'pandas.core.panel.Panel'&gt;
Dimensions: 4 (items) x 12 (major_axis) x 2 (minor_axis)
Items axis: X to Y
Major_axis axis: 0 to 11
Minor_axis axis: A to B"><pre class="notranslate"><code class="notranslate"># create data
import pandas as pd
df1 = pd.DataFrame({'A' : [1, 2, 3], 'B' : [2, 5, 6]}, index={0, 1, 2})
df2 = pd.DataFrame({'A' : [1, 2, 3], 'B' : [2, 5, 6]}, index={3, 4, 5})
df3 = pd.DataFrame({'A' : [5, 2, 3], 'B' : [2, 5, 6]}, index={6, 7, 8})
df4 = pd.DataFrame({'A' : [6, 2, 3], 'B' : [2, 5, 6]}, index={9, 10, 11})

pan1 = pd.Panel({'X' : df1, 'Y': df2})
pan2 = pd.Panel({'X' : df3, 'Y': df4})

# concat these two panels above
pan3 = pd.concat([pan1, pan2])

pan3
Output:
&lt;class 'pandas.core.panel.Panel'&gt;
Dimensions: 4 (items) x 12 (major_axis) x 2 (minor_axis)
Items axis: X to Y
Major_axis axis: 0 to 11
Minor_axis axis: A to B
</code></pre></div>
<p dir="auto"><strong>Note that the <code class="notranslate">Items</code> axis for <code class="notranslate">pan3</code> is of length 4, while <code class="notranslate">pan1</code> and <code class="notranslate">pan2</code> both have <code class="notranslate">Items</code> axis of length 2.</strong></p>
<p dir="auto">Looking at <code class="notranslate">pan3</code>'s <code class="notranslate">minor_axis</code>, I get duplicated columns in the frame below.  <strong>This is my problem.</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pan3.loc[:, :, 'B']"><pre class="notranslate"><code class="notranslate">pan3.loc[:, :, 'B']
</code></pre></div>
<p dir="auto">Screenshot: See this <a href="http://stackoverflow.com/questions/34652835/pandas-how-to-concatenate-two-panels-without-duplicating-items-axis-i-e-colum" rel="nofollow">link on SO</a></p>
<p dir="auto"><strong>What I actually want to see</strong> can be replicated as follows in a more complicated way... (Not more duplicated columns in the screenshot):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="df5 = pd.concat([df1, df3])
df6 = pd.concat([df2, df4])
pan4 = pd.Panel({'X':df5, 'Y':df6})
pan4.loc[:, :, 'B']"><pre class="notranslate"><code class="notranslate">df5 = pd.concat([df1, df3])
df6 = pd.concat([df2, df4])
pan4 = pd.Panel({'X':df5, 'Y':df6})
pan4.loc[:, :, 'B']
</code></pre></div>
<p dir="auto">Screenshot: See this <a href="http://stackoverflow.com/questions/34652835/pandas-how-to-concatenate-two-panels-without-duplicating-items-axis-i-e-colum" rel="nofollow">link on SO</a></p>
<p dir="auto"><strong>Is this something that can be done with <code class="notranslate">pd.concat</code>?</strong> Thanks guys.</p>
<p dir="auto">I get a NameError exception when I try to filter DataFrame by selected index values (inside IPython session). You can see that <a href="http://www.datafilehost.com/d/a5c78493" rel="nofollow"><code class="notranslate">valid</code></a> is <code class="notranslate">numpy.array</code> while <a href="http://www.datafilehost.com/d/cf3704a0" rel="nofollow"><code class="notranslate">lab</code></a> is a <code class="notranslate">pandas.DataFrame</code> object. Both of them are initialized and accessible. However I cannot put them together. Here is the error:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [51]: valid
Out[51]: 
array([38661, 44593, 38705, 38918, 38727, 38757, 38751, 38777, 38787,
       ...,    
       45328, 45337, 43645, 43694, 43701])

In [52]: lab
Out[52]: 
         0
39333   -1
39173   -1
42756   -1
39633   -1
38661   -1
44801   81
...    ...
39379   -1
39742   -1
44765  108
44279   -1
40584   -1
41047   -1
41833   98

[3299 rows x 1 columns]

In [53]: lab[lab.index.map(lambda x: x in valid)]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/home/vitaly/progs/vnii_gochs/venv/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in &lt;module&gt;()
----&gt; 1 lab[lab.index.map(lambda x: x in valid)]

/home/vitaly/progs/vnii_gochs/venv/lib/python2.7/site-packages/pandas/core/index.pyc in map(self, mapper)
   1558 
   1559     def map(self, mapper):
-&gt; 1560         return self._arrmap(self.values, mapper)
   1561 
   1562     def isin(self, values, level=None):

/home/vitaly/progs/vnii_gochs/venv/lib/python2.7/site-packages/pandas/algos.so in pandas.algos.arrmap_int64 (pandas/algos.c:78469)()

/home/vitaly/progs/vnii_gochs/venv/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in &lt;lambda&gt;(x)
----&gt; 1 lab[lab.index.map(lambda x: x in valid)]

NameError: global name 'valid' is not defined"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">51</span>]: <span class="pl-s1">valid</span>
<span class="pl-v">Out</span>[<span class="pl-c1">51</span>]: 
<span class="pl-en">array</span>([<span class="pl-c1">38661</span>, <span class="pl-c1">44593</span>, <span class="pl-c1">38705</span>, <span class="pl-c1">38918</span>, <span class="pl-c1">38727</span>, <span class="pl-c1">38757</span>, <span class="pl-c1">38751</span>, <span class="pl-c1">38777</span>, <span class="pl-c1">38787</span>,
       ...,    
       <span class="pl-c1">45328</span>, <span class="pl-c1">45337</span>, <span class="pl-c1">43645</span>, <span class="pl-c1">43694</span>, <span class="pl-c1">43701</span>])

<span class="pl-v">In</span> [<span class="pl-c1">52</span>]: <span class="pl-s1">lab</span>
<span class="pl-v">Out</span>[<span class="pl-c1">52</span>]: 
         <span class="pl-c1">0</span>
<span class="pl-c1">39333</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">39173</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">42756</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">39633</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">38661</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">44801</span>   <span class="pl-c1">81</span>
...    ...
<span class="pl-c1">39379</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">39742</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">44765</span>  <span class="pl-c1">108</span>
<span class="pl-c1">44279</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">40584</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">41047</span>   <span class="pl-c1">-</span><span class="pl-c1">1</span>
<span class="pl-c1">41833</span>   <span class="pl-c1">98</span>

[<span class="pl-c1">3299</span> <span class="pl-s1">rows</span> <span class="pl-s1">x</span> <span class="pl-c1">1</span> <span class="pl-s1">columns</span>]

<span class="pl-v">In</span> [<span class="pl-c1">53</span>]: <span class="pl-s1">lab</span>[<span class="pl-s1">lab</span>.<span class="pl-s1">index</span>.<span class="pl-en">map</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span> <span class="pl-c1">in</span> <span class="pl-s1">valid</span>)]
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">NameError</span>                                 <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">vitaly</span><span class="pl-c1">/</span><span class="pl-s1">progs</span><span class="pl-c1">/</span><span class="pl-s1">vnii_gochs</span><span class="pl-c1">/</span><span class="pl-s1">venv</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">django</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">management</span><span class="pl-c1">/</span><span class="pl-s1">commands</span><span class="pl-c1">/</span><span class="pl-s1">shell</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">lab</span>[<span class="pl-s1">lab</span>.<span class="pl-s1">index</span>.<span class="pl-en">map</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span> <span class="pl-c1">in</span> <span class="pl-s1">valid</span>)]

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">vitaly</span><span class="pl-c1">/</span><span class="pl-s1">progs</span><span class="pl-c1">/</span><span class="pl-s1">vnii_gochs</span><span class="pl-c1">/</span><span class="pl-s1">venv</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">index</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">map</span>(<span class="pl-s1">self</span>, <span class="pl-s1">mapper</span>)
   <span class="pl-c1">1558</span> 
   <span class="pl-c1">1559</span>     <span class="pl-k">def</span> <span class="pl-en">map</span>(<span class="pl-s1">self</span>, <span class="pl-s1">mapper</span>):
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1560</span>         <span class="pl-s1">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_arrmap</span>(<span class="pl-s1">self</span>.<span class="pl-s1">values</span>, <span class="pl-s1">mapper</span>)
   <span class="pl-c1">1561</span> 
   <span class="pl-c1">1562</span>     <span class="pl-k">def</span> <span class="pl-en">isin</span>(<span class="pl-s1">self</span>, <span class="pl-s1">values</span>, <span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">vitaly</span><span class="pl-c1">/</span><span class="pl-s1">progs</span><span class="pl-c1">/</span><span class="pl-s1">vnii_gochs</span><span class="pl-c1">/</span><span class="pl-s1">venv</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">algos</span>.<span class="pl-s1">so</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">algos</span>.<span class="pl-en">arrmap_int64</span> (<span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">algos</span>.<span class="pl-s1">c</span>:<span class="pl-c1">78469</span>)()

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">vitaly</span><span class="pl-c1">/</span><span class="pl-s1">progs</span><span class="pl-c1">/</span><span class="pl-s1">vnii_gochs</span><span class="pl-c1">/</span><span class="pl-s1">venv</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">django</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">management</span><span class="pl-c1">/</span><span class="pl-s1">commands</span><span class="pl-c1">/</span><span class="pl-s1">shell</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">lambda</span><span class="pl-c1">&gt;</span>(<span class="pl-s1">x</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">lab</span>[<span class="pl-s1">lab</span>.<span class="pl-s1">index</span>.<span class="pl-en">map</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span> <span class="pl-c1">in</span> <span class="pl-s1">valid</span>)]

<span class="pl-v">NameError</span>: <span class="pl-s1">global</span> <span class="pl-s1">name</span> <span class="pl-s">'valid'</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-s1">defined</span></pre></div>
<p dir="auto">What's wrong with this code? I use pandas 0.15.1.<br>
(This issue is a duplicate of SO's question <a href="http://stackoverflow.com/questions/27637825/variable-visibility-issue-with-pandas-and-ipython/27643446#27643446" rel="nofollow">http://stackoverflow.com/questions/27637825/variable-visibility-issue-with-pandas-and-ipython/27643446#27643446</a>)</p>