<p dir="auto">As shown in the example below, when passing in two series with the same name to <code class="notranslate">concat</code> you end up with duplicates of the last series passed in.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [42]: pd.__version__
Out[42]: '0.10.1'

In [43]: dates = pd.date_range('01-Jan-2013','01-Dec-2013', freq='MS')
    ...: L = pd.TimeSeries('L', dates, name='LeftRight')
    ...: R = pd.TimeSeries('R', dates, name='LeftRight')
    ...: 

In [44]: L
Out[44]: 
2013-01-01    L
2013-02-01    L
2013-03-01    L
2013-04-01    L
2013-05-01    L
2013-06-01    L
2013-07-01    L
2013-08-01    L
2013-09-01    L
2013-10-01    L
2013-11-01    L
2013-12-01    L
Freq: MS, Name: LeftRight

In [45]: R
Out[45]: 
2013-01-01    R
2013-02-01    R
2013-03-01    R
2013-04-01    R
2013-05-01    R
2013-06-01    R
2013-07-01    R
2013-08-01    R
2013-09-01    R
2013-10-01    R
2013-11-01    R
2013-12-01    R
Freq: MS, Name: LeftRight

In [46]: pd.concat([L,R], axis=1)
Out[46]: 
           LeftRight LeftRight
2013-01-01         R         R
2013-02-01         R         R
2013-03-01         R         R
2013-04-01         R         R
2013-05-01         R         R
2013-06-01         R         R
2013-07-01         R         R
2013-08-01         R         R
2013-09-01         R         R
2013-10-01         R         R
2013-11-01         R         R
2013-12-01         R         R

In [47]: pd.concat([L,R], axis=1, keys=['Left','Right'])
Out[47]: 
           Left Right
2013-01-01    L     R
2013-02-01    L     R
2013-03-01    L     R
2013-04-01    L     R
2013-05-01    L     R
2013-06-01    L     R
2013-07-01    L     R
2013-08-01    L     R
2013-09-01    L     R
2013-10-01    L     R
2013-11-01    L     R
2013-12-01    L     R
"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">42</span>]: <span class="pl-s1">pd</span>.<span class="pl-s1">__version__</span>
<span class="pl-v">Out</span>[<span class="pl-c1">42</span>]: <span class="pl-s">'0.10.1'</span>

<span class="pl-v">In</span> [<span class="pl-c1">43</span>]: <span class="pl-s1">dates</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'01-Jan-2013'</span>,<span class="pl-s">'01-Dec-2013'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'MS'</span>)
    ...: <span class="pl-v">L</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">TimeSeries</span>(<span class="pl-s">'L'</span>, <span class="pl-s1">dates</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'LeftRight'</span>)
    ...: <span class="pl-v">R</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">TimeSeries</span>(<span class="pl-s">'R'</span>, <span class="pl-s1">dates</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'LeftRight'</span>)
    ...: 

<span class="pl-v">In</span> [<span class="pl-c1">44</span>]: <span class="pl-v">L</span>
<span class="pl-v">Out</span>[<span class="pl-c1">44</span>]: 
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">02</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">03</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">05</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">06</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">07</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">08</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">09</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">10</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">11</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">12</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>
<span class="pl-v">Freq</span>: <span class="pl-v">MS</span>, <span class="pl-v">Name</span>: <span class="pl-v">LeftRight</span>

<span class="pl-v">In</span> [<span class="pl-c1">45</span>]: <span class="pl-v">R</span>
<span class="pl-v">Out</span>[<span class="pl-c1">45</span>]: 
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">02</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">03</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">05</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">06</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">07</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">08</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">09</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">10</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">11</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">12</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">R</span>
<span class="pl-v">Freq</span>: <span class="pl-v">MS</span>, <span class="pl-v">Name</span>: <span class="pl-v">LeftRight</span>

<span class="pl-v">In</span> [<span class="pl-c1">46</span>]: <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-v">L</span>,<span class="pl-v">R</span>], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">46</span>]: 
           <span class="pl-v">LeftRight</span> <span class="pl-v">LeftRight</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">02</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">03</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">05</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">06</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">07</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">08</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">09</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">10</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">11</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">12</span><span class="pl-c1">-</span><span class="pl-c1">01</span>         <span class="pl-v">R</span>         <span class="pl-v">R</span>

<span class="pl-v">In</span> [<span class="pl-c1">47</span>]: <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-v">L</span>,<span class="pl-v">R</span>], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>, <span class="pl-s1">keys</span><span class="pl-c1">=</span>[<span class="pl-s">'Left'</span>,<span class="pl-s">'Right'</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">47</span>]: 
           <span class="pl-v">Left</span> <span class="pl-v">Right</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">01</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">02</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">03</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">05</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">06</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">07</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">08</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">09</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">10</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">11</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">12</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-v">L</span>     <span class="pl-v">R</span></pre></div>
<p dir="auto">Motivating from <a href="http://stackoverflow.com/questions/26762100/reconstruct-a-categorical-variable-from-dummies-in-pandas" rel="nofollow">SO</a></p>
<p dir="auto">This is the inverse of <code class="notranslate">pd.get_dummies</code>. So maybe <code class="notranslate">invert_dummies</code> is better?<br>
I think this name makes more sense though.</p>
<p dir="auto">This seems a reasonable way to do it. Am I missing anything?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [46]: s = Series(list('aaabbbccddefgh')).astype('category')

In [47]: s
Out[47]: 
0     a
1     a
2     a
3     b
4     b
5     b
6     c
7     c
8     d
9     d
10    e
11    f
12    g
13    h
dtype: category
Categories (8, object): [a &lt; b &lt; c &lt; d &lt; e &lt; f &lt; g &lt; h]

In [48]: df = pd.get_dummies(s)

In [49]: df
Out[49]: 
    a  b  c  d  e  f  g  h
0   1  0  0  0  0  0  0  0
1   1  0  0  0  0  0  0  0
2   1  0  0  0  0  0  0  0
3   0  1  0  0  0  0  0  0
4   0  1  0  0  0  0  0  0
5   0  1  0  0  0  0  0  0
6   0  0  1  0  0  0  0  0
7   0  0  1  0  0  0  0  0
8   0  0  0  1  0  0  0  0
9   0  0  0  1  0  0  0  0
10  0  0  0  0  1  0  0  0
11  0  0  0  0  0  1  0  0
12  0  0  0  0  0  0  1  0
13  0  0  0  0  0  0  0  1

In [50]: x = df.stack()

# I don't think you actually need to specify ALL of the categories here, as by definition
# they are in the dummy matrix to start (and hence the column index)
In [51]: Series(pd.Categorical(x[x!=0].index.get_level_values(1)))
Out[51]: 
0     a
1     a
2     a
3     b
4     b
5     b
6     c
7     c
8     d
9     d
10    e
11    f
12    g
13    h
Name: level_1, dtype: category
Categories (8, object): [a &lt; b &lt; c &lt; d &lt; e &lt; f &lt; g &lt; h]"><pre class="notranslate"><code class="notranslate">In [46]: s = Series(list('aaabbbccddefgh')).astype('category')

In [47]: s
Out[47]: 
0     a
1     a
2     a
3     b
4     b
5     b
6     c
7     c
8     d
9     d
10    e
11    f
12    g
13    h
dtype: category
Categories (8, object): [a &lt; b &lt; c &lt; d &lt; e &lt; f &lt; g &lt; h]

In [48]: df = pd.get_dummies(s)

In [49]: df
Out[49]: 
    a  b  c  d  e  f  g  h
0   1  0  0  0  0  0  0  0
1   1  0  0  0  0  0  0  0
2   1  0  0  0  0  0  0  0
3   0  1  0  0  0  0  0  0
4   0  1  0  0  0  0  0  0
5   0  1  0  0  0  0  0  0
6   0  0  1  0  0  0  0  0
7   0  0  1  0  0  0  0  0
8   0  0  0  1  0  0  0  0
9   0  0  0  1  0  0  0  0
10  0  0  0  0  1  0  0  0
11  0  0  0  0  0  1  0  0
12  0  0  0  0  0  0  1  0
13  0  0  0  0  0  0  0  1

In [50]: x = df.stack()

# I don't think you actually need to specify ALL of the categories here, as by definition
# they are in the dummy matrix to start (and hence the column index)
In [51]: Series(pd.Categorical(x[x!=0].index.get_level_values(1)))
Out[51]: 
0     a
1     a
2     a
3     b
4     b
5     b
6     c
7     c
8     d
9     d
10    e
11    f
12    g
13    h
Name: level_1, dtype: category
Categories (8, object): [a &lt; b &lt; c &lt; d &lt; e &lt; f &lt; g &lt; h]
</code></pre></div>
<p dir="auto">NB. this is buggy ATM.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [51]: Series(pd.Categorical(x[x!=0].index.get_level_values(1)),categories=df.categories)"><pre class="notranslate"><code class="notranslate">In [51]: Series(pd.Categorical(x[x!=0].index.get_level_values(1)),categories=df.categories)
</code></pre></div>