Issue 1:
I am trying to concatenating two Panels with duplicate Items (but different major_axes) together, without actually having to duplicate items... Did some searching but couldn't find much on SO.

Unfortunately I cannot upload pics to github at the moment.. But screens are attached here.

To illustrate what I mean:

# 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:
<class 'pandas.core.panel.Panel'>
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

Note that the Items axis for pan3 is of length 4, while pan1 and pan2 both have Items axis of length 2.

Looking at pan3's minor_axis, I get duplicated columns in the frame below. This is my problem.:

pan3.loc[:, :, 'B']

Screenshot: See this link on SO

What I actually want to see can be replicated as follows in a more complicated way... (Not more duplicated columns in the screenshot):

df5 = pd.concat([df1, df3])
df6 = pd.concat([df2, df4])
pan4 = pd.Panel({'X':df5, 'Y':df6})
pan4.loc[:, :, 'B']

Screenshot: See this link on SO

Is this something that can be done with pd.concat? Thanks guys.

Issue 2:
I get a NameError exception when I try to filter DataFrame by selected index values (inside IPython session). You can see that valid is numpy.array while lab is a pandas.DataFrame object. Both of them are initialized and accessible. However I cannot put them together. Here is the error:

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 <module>()
----> 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):
-> 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 <lambda>(x)
----> 1 lab[lab.index.map(lambda x: x in valid)]

NameError: global name 'valid' is not defined

What's wrong with this code? I use pandas 0.15.1.

(This issue is a duplicate of SO's question http://stackoverflow.com/questions/27637825/variable-visibility-issue-with-pandas-and-ipython/27643446#27643446)