<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

df = pd.DataFrame(
    np.ones([6, 4], dtype=int),
    columns=pd.MultiIndex.from_product([['A', 'B'], [1, 2]])
)

(
    df
    .groupby(level=0, axis=1)
    .apply(
        lambda df: pd.concat(
            [df.xs(df.name, axis=1), df.sum(axis=1).to_frame('Total')], 
            axis=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">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(
    <span class="pl-s1">np</span>.<span class="pl-en">ones</span>([<span class="pl-c1">6</span>, <span class="pl-c1">4</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int</span>),
    <span class="pl-s1">columns</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_product</span>([[<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>]])
)

(
    <span class="pl-s1">df</span>
    .<span class="pl-en">groupby</span>(<span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
    .<span class="pl-en">apply</span>(
        <span class="pl-k">lambda</span> <span class="pl-s1">df</span>: <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>(
            [<span class="pl-s1">df</span>.<span class="pl-en">xs</span>(<span class="pl-s1">df</span>.<span class="pl-s1">name</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>), <span class="pl-s1">df</span>.<span class="pl-en">sum</span>(<span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-en">to_frame</span>(<span class="pl-s">'Total'</span>)], 
            <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>
        )
    )
)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The code above produces the error:</p>
<blockquote>
<p dir="auto">cannot reindex from a duplicate axis</p>
</blockquote>
<p dir="auto">I believe this is a bug because, as described below, essentially the same operations can be successfully run along the other axis.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">It should, as far as I can tell, produce the following output:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/15697539/26962477-b92ed344-4d29-11e7-9cd8-ca5406eee097.png"><img src="https://user-images.githubusercontent.com/15697539/26962477-b92ed344-4d29-11e7-9cd8-ca5406eee097.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">The desired output can be obtained when working on the transposed DataFrame along the <code class="notranslate">index</code> rather than the <code class="notranslate">columns</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="(
    df
    .T
    .groupby(level=0)
    .apply(
        lambda df: pd.concat(
            [df.xs(df.name), df.sum().to_frame('Total').T]
        )
    )
    .T
)"><pre class="notranslate">(
    <span class="pl-s1">df</span>
    .<span class="pl-v">T</span>
    .<span class="pl-en">groupby</span>(<span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
    .<span class="pl-en">apply</span>(
        <span class="pl-k">lambda</span> <span class="pl-s1">df</span>: <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>(
            [<span class="pl-s1">df</span>.<span class="pl-en">xs</span>(<span class="pl-s1">df</span>.<span class="pl-s1">name</span>), <span class="pl-s1">df</span>.<span class="pl-en">sum</span>().<span class="pl-en">to_frame</span>(<span class="pl-s">'Total'</span>).<span class="pl-v">T</span>]
        )
    )
    .<span class="pl-v">T</span>
)</pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<p dir="auto">pd.show_versions()<br>
pd.show_versions()</p>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 2.7.9.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 8<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.20.2<br>
pytest: None<br>
pip: 9.0.1<br>
setuptools: 34.3.3<br>
Cython: None<br>
numpy: 1.13.0<br>
scipy: 0.19.0<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.0<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.0.0<br>
openpyxl: None<br>
xlrd: 1.0.0<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: 0.999<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: 2.7.1 (dt dec pq3 ext lo64)<br>
jinja2: 2.9.5<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<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

df = pd.DataFrame([['2018-01-01','MSFT','short'],
                  ['2018-01-01','MSFT','long'],
                  ['2018-01-01','MSFT',pd.np.NaN],
                  ['2018-01-01','AAPL','short'],
                  ['2018-01-01','AAPL',pd.np.NaN],
                  ['2018-01-02','AAPL','short'],
                  ['2018-01-01','TSLA','neutral'],
                  ['2018-01-02','TSLA',pd.np.NaN]],
                columns=['date','symbol','status'])

df['date'] = pd.to_datetime(df['date'])
df = df.set_index(['date','symbol'])
df.groupby('symbol')['status'].ffill()"><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">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([[<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'MSFT'</span>,<span class="pl-s">'short'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'MSFT'</span>,<span class="pl-s">'long'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'MSFT'</span>,<span class="pl-s1">pd</span>.<span class="pl-s1">np</span>.<span class="pl-v">NaN</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'AAPL'</span>,<span class="pl-s">'short'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'AAPL'</span>,<span class="pl-s1">pd</span>.<span class="pl-s1">np</span>.<span class="pl-v">NaN</span>],
                  [<span class="pl-s">'2018-01-02'</span>,<span class="pl-s">'AAPL'</span>,<span class="pl-s">'short'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'TSLA'</span>,<span class="pl-s">'neutral'</span>],
                  [<span class="pl-s">'2018-01-02'</span>,<span class="pl-s">'TSLA'</span>,<span class="pl-s1">pd</span>.<span class="pl-s1">np</span>.<span class="pl-v">NaN</span>]],
                <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'date'</span>,<span class="pl-s">'symbol'</span>,<span class="pl-s">'status'</span>])

<span class="pl-s1">df</span>[<span class="pl-s">'date'</span>] <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_datetime</span>(<span class="pl-s1">df</span>[<span class="pl-s">'date'</span>])
<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'date'</span>,<span class="pl-s">'symbol'</span>])
<span class="pl-s1">df</span>.<span class="pl-en">groupby</span>(<span class="pl-s">'symbol'</span>)[<span class="pl-s">'status'</span>].<span class="pl-en">ffill</span>()</pre></div>
<h4 dir="auto">Raised exception</h4>
<details>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
&lt;ipython-input-58-2fe0989150cf&gt; in &lt;module&gt;()
     13 df['date'] = pd.to_datetime(df['date'])
     14 df = df.set_index(['date','symbol'])
---&gt; 15 df.groupby('symbol')['status'].ffill()

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in pad(self, limit)
   1362         DataFrame.fillna
   1363         &quot;&quot;&quot;
-&gt; 1364         return self.apply(lambda x: x.ffill(limit=limit))
   1365     ffill = pad
   1366 

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in apply(self, func, *args, **kwargs)
   3110                       examples=_apply_docs['series_examples']))
   3111     def apply(self, func, *args, **kwargs):
-&gt; 3112         return super(SeriesGroupBy, self).apply(func, *args, **kwargs)
   3113 
   3114     @Appender(_agg_doc)

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in apply(self, func, *args, **kwargs)
    803         # ignore SettingWithCopy here in case the user mutates
    804         with option_context('mode.chained_assignment', None):
--&gt; 805             return self._python_apply_general(f)
    806 
    807     def _python_apply_general(self, f):

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in _python_apply_general(self, f)
    812             keys,
    813             values,
--&gt; 814             not_indexed_same=mutated or self.mutated)
    815 
    816     def _iterate_slices(self):

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in _wrap_applied_output(self, keys, values, not_indexed_same)
   3250         if isinstance(values[0], (Series, dict)):
   3251             return self._concat_objects(keys, values,
-&gt; 3252                                         not_indexed_same=not_indexed_same)
   3253         elif isinstance(values[0], DataFrame):
   3254             # possible that Series -&gt; DataFrame by applied function

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in _concat_objects(self, keys, values, not_indexed_same)
    978 
    979             if isinstance(result, Series):
--&gt; 980                 result = result.reindex(ax)
    981             else:
    982 

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/series.pyc in reindex(self, index, **kwargs)
   2679     @Appender(generic._shared_docs['reindex'] % _shared_doc_kwargs)
   2680     def reindex(self, index=None, **kwargs):
-&gt; 2681         return super(Series, self).reindex(index=index, **kwargs)
   2682 
   2683     @Appender(generic._shared_docs['fillna'] % _shared_doc_kwargs)

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/generic.pyc in reindex(self, *args, **kwargs)
   3021         # perform the reindex on the axes
   3022         return self._reindex_axes(axes, level, limit, tolerance, method,
-&gt; 3023                                   fill_value, copy).__finalize__(self)
   3024 
   3025     def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/generic.pyc in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
   3034             ax = self._get_axis(a)
   3035             new_index, indexer = ax.reindex(labels, level=level, limit=limit,
-&gt; 3036                                             tolerance=tolerance, method=method)
   3037 
   3038             axis = self._get_axis_number(a)

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/indexes/multi.pyc in reindex(self, target, method, level, limit, tolerance)
   1901                                                tolerance=tolerance)
   1902                 else:
-&gt; 1903                     raise Exception(&quot;cannot handle a non-unique multi-index!&quot;)
   1904 
   1905         if not isinstance(target, MultiIndex):

Exception: cannot handle a non-unique multi-index!"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
&lt;ipython-input-58-2fe0989150cf&gt; in &lt;module&gt;()
     13 df['date'] = pd.to_datetime(df['date'])
     14 df = df.set_index(['date','symbol'])
---&gt; 15 df.groupby('symbol')['status'].ffill()

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in pad(self, limit)
   1362         DataFrame.fillna
   1363         """
-&gt; 1364         return self.apply(lambda x: x.ffill(limit=limit))
   1365     ffill = pad
   1366 

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in apply(self, func, *args, **kwargs)
   3110                       examples=_apply_docs['series_examples']))
   3111     def apply(self, func, *args, **kwargs):
-&gt; 3112         return super(SeriesGroupBy, self).apply(func, *args, **kwargs)
   3113 
   3114     @Appender(_agg_doc)

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in apply(self, func, *args, **kwargs)
    803         # ignore SettingWithCopy here in case the user mutates
    804         with option_context('mode.chained_assignment', None):
--&gt; 805             return self._python_apply_general(f)
    806 
    807     def _python_apply_general(self, f):

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in _python_apply_general(self, f)
    812             keys,
    813             values,
--&gt; 814             not_indexed_same=mutated or self.mutated)
    815 
    816     def _iterate_slices(self):

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in _wrap_applied_output(self, keys, values, not_indexed_same)
   3250         if isinstance(values[0], (Series, dict)):
   3251             return self._concat_objects(keys, values,
-&gt; 3252                                         not_indexed_same=not_indexed_same)
   3253         elif isinstance(values[0], DataFrame):
   3254             # possible that Series -&gt; DataFrame by applied function

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/groupby.pyc in _concat_objects(self, keys, values, not_indexed_same)
    978 
    979             if isinstance(result, Series):
--&gt; 980                 result = result.reindex(ax)
    981             else:
    982 

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/series.pyc in reindex(self, index, **kwargs)
   2679     @Appender(generic._shared_docs['reindex'] % _shared_doc_kwargs)
   2680     def reindex(self, index=None, **kwargs):
-&gt; 2681         return super(Series, self).reindex(index=index, **kwargs)
   2682 
   2683     @Appender(generic._shared_docs['fillna'] % _shared_doc_kwargs)

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/generic.pyc in reindex(self, *args, **kwargs)
   3021         # perform the reindex on the axes
   3022         return self._reindex_axes(axes, level, limit, tolerance, method,
-&gt; 3023                                   fill_value, copy).__finalize__(self)
   3024 
   3025     def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/generic.pyc in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
   3034             ax = self._get_axis(a)
   3035             new_index, indexer = ax.reindex(labels, level=level, limit=limit,
-&gt; 3036                                             tolerance=tolerance, method=method)
   3037 
   3038             axis = self._get_axis_number(a)

/home/greg/anaconda2/lib/python2.7/site-packages/pandas/core/indexes/multi.pyc in reindex(self, target, method, level, limit, tolerance)
   1901                                                tolerance=tolerance)
   1902                 else:
-&gt; 1903                     raise Exception("cannot handle a non-unique multi-index!")
   1904 
   1905         if not isinstance(target, MultiIndex):

Exception: cannot handle a non-unique multi-index!
</code></pre></div>
</details>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Performing <code class="notranslate">ffill()</code> does not forward fill values as intended. The index has duplicate values, the expectation is that the values will be filled according to the order the rows are in already.</p>
<p dir="auto">Duplicate index values are possible when using high frequency time intervals.</p>
<h4 dir="auto">Expected Output</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="df = pd.DataFrame([['2018-01-01','MSFT','short'],
                  ['2018-01-01','MSFT','long'],
                  ['2018-01-01','MSFT','long'],
                  ['2018-01-01','AAPL','short'],
                  ['2018-01-01','AAPL','short'],
                  ['2018-01-02','AAPL','short'],
                  ['2018-01-01','TSLA','neutral'],
                  ['2018-01-02','TSLA','neutral']],
                columns=['date','symbol','status'])

df['date'] = pd.to_datetime(df['date'])"><pre class="notranslate"><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-s">'2018-01-01'</span>,<span class="pl-s">'MSFT'</span>,<span class="pl-s">'short'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'MSFT'</span>,<span class="pl-s">'long'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'MSFT'</span>,<span class="pl-s">'long'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'AAPL'</span>,<span class="pl-s">'short'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'AAPL'</span>,<span class="pl-s">'short'</span>],
                  [<span class="pl-s">'2018-01-02'</span>,<span class="pl-s">'AAPL'</span>,<span class="pl-s">'short'</span>],
                  [<span class="pl-s">'2018-01-01'</span>,<span class="pl-s">'TSLA'</span>,<span class="pl-s">'neutral'</span>],
                  [<span class="pl-s">'2018-01-02'</span>,<span class="pl-s">'TSLA'</span>,<span class="pl-s">'neutral'</span>]],
                <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'date'</span>,<span class="pl-s">'symbol'</span>,<span class="pl-s">'status'</span>])

<span class="pl-s1">df</span>[<span class="pl-s">'date'</span>] <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_datetime</span>(<span class="pl-s1">df</span>[<span class="pl-s">'date'</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.14.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.13.0-31-generic<br>
machine: x86_64<br>
processor: x86_64<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_AU.UTF-8<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.22.0<br>
pytest: 3.2.1<br>
pip: 9.0.1<br>
setuptools: 36.5.0.post20170921<br>
Cython: 0.26.1<br>
numpy: 1.14.0<br>
scipy: 0.19.1<br>
pyarrow: None<br>
xarray: None<br>
IPython: 5.4.1<br>
sphinx: 1.6.3<br>
patsy: 0.4.1<br>
dateutil: 2.6.1<br>
pytz: 2017.3<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.4.2<br>
numexpr: 2.6.2<br>
feather: None<br>
matplotlib: 2.1.0<br>
openpyxl: 2.4.8<br>
xlrd: 1.1.0<br>
xlwt: 1.3.0<br>
xlsxwriter: 1.0.2<br>
lxml: 4.1.0<br>
bs4: 4.6.0<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.1.13<br>
pymysql: None<br>
psycopg2: 2.7.3.2 (dt dec pq3 ext lo64)<br>
jinja2: 2.9.6<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">This also happens with <code class="notranslate">axis=1</code>.</p>
<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

df = pd.DataFrame(
    np.ones([6, 4], dtype=int),
    columns=pd.MultiIndex.from_product([['A', 'B'], [1, 2]])
)

(
    df
    .groupby(level=0, axis=1)
    .apply(
        lambda df: 2*df.xs(df.name, axis=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">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(
    <span class="pl-s1">np</span>.<span class="pl-en">ones</span>([<span class="pl-c1">6</span>, <span class="pl-c1">4</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int</span>),
    <span class="pl-s1">columns</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_product</span>([[<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>]])
)

(
    <span class="pl-s1">df</span>
    .<span class="pl-en">groupby</span>(<span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
    .<span class="pl-en">apply</span>(
        <span class="pl-k">lambda</span> <span class="pl-s1">df</span>: <span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">df</span>.<span class="pl-en">xs</span>(<span class="pl-s1">df</span>.<span class="pl-s1">name</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
    )
)</pre></div>
<details>
<div class="highlight highlight-text-python-traceback notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-12-e7c022399f89&gt; in &lt;module&gt;()
      3     .groupby(level=0, axis=1)
      4     .apply(
----&gt; 5         lambda df: 2*df.xs(df.name, axis=1)
      6     )
      7 )

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in apply(self, func, *args, **kwargs)
    882         # ignore SettingWithCopy here in case the user mutates
    883         with option_context('mode.chained_assignment', None):
--&gt; 884             return self._python_apply_general(f)
    885
    886     def _python_apply_general(self, f):

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in _python_apply_general(self, f)
    891             keys,
    892             values,
--&gt; 893             not_indexed_same=mutated or self.mutated)
    894
    895     def _iterate_slices(self):

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in _wrap_applied_output(self, keys, values, not_indexed_same)
   3920         elif isinstance(v, DataFrame):
   3921             return self._concat_objects(keys, values,
-&gt; 3922                                         not_indexed_same=not_indexed_same)
   3923         elif self.grouper.groupings is not None:
   3924             if len(self.grouper.groupings) &gt; 1:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in _concat_objects(self, keys, values, not_indexed_same)
   1085                     result = result.take(indexer, axis=self.axis)
   1086                 else:
-&gt; 1087                     result = result.reindex(ax, axis=self.axis)
   1088
   1089         elif self.group_keys:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    145         @wraps(func)
    146         def wrapper(*args, **kwargs):
--&gt; 147             return func(*args, **kwargs)
    148
    149         if not PY2:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/frame.py in reindex(self, *args, **kwargs)
   2979         kwargs.pop('axis', None)
   2980         kwargs.pop('labels', None)
-&gt; 2981         return super(DataFrame, self).reindex(**kwargs)
   2982
   2983     @Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/generic.py in reindex(self, *args, **kwargs)
   3356         # perform the reindex on the axes
   3357         return self._reindex_axes(axes, level, limit, tolerance, method,
-&gt; 3358                                   fill_value, copy).__finalize__(self)
   3359
   3360     def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/frame.py in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
   2909         if columns is not None:
   2910             frame = frame._reindex_columns(columns, method, copy, level,
-&gt; 2911                                            fill_value, limit, tolerance)
   2912
   2913         index = axes['index']

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/frame.py in _reindex_columns(self, new_columns, method, copy, level, fill_value, limit, tolerance)
   2934         return self._reindex_with_indexers({1: [new_columns, indexer]},
   2935                                            copy=copy, fill_value=fill_value,
-&gt; 2936                                            allow_dups=False)
   2937
   2938     def _reindex_multi(self, axes, copy, fill_value):

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/generic.py in _reindex_with_indexers(self, reindexers, fill_value, copy, allow_dups)
   3477                                                 fill_value=fill_value,
   3478                                                 allow_dups=allow_dups,
-&gt; 3479                                                 copy=copy)
   3480
   3481         if copy and new_data is self._data:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/internals.py in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups, copy)
   4125         # some axes don't allow reindexing with dups
   4126         if not allow_dups:
-&gt; 4127             self.axes[axis]._can_reindex(indexer)
   4128
   4129         if axis &gt;= self.ndim:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/indexes/base.py in _can_reindex(self, indexer)
   2940         # trying to reindex on an axis with duplicates
   2941         if not self.is_unique and len(indexer):
-&gt; 2942             raise ValueError(&quot;cannot reindex from a duplicate axis&quot;)
   2943
   2944     def reindex(self, target, method=None, level=None, limit=None,

ValueError: cannot reindex from a duplicate axis"><pre class="notranslate">---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-12-e7c022399f89&gt; in &lt;module&gt;()
      <span class="pl-c1">3</span>     .groupby(<span class="pl-v">level</span><span class="pl-k">=</span><span class="pl-c1">0</span>, <span class="pl-v">axis</span><span class="pl-k">=</span><span class="pl-c1">1</span>)
      <span class="pl-c1">4</span>     .apply(
----&gt; 5         lambda df: 2*df.xs(df.name, axis=1)
      <span class="pl-c1">6</span>     )
      <span class="pl-c1">7</span> )

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in apply(self, func, *args, **kwargs)
    <span class="pl-c1">882</span>         <span class="pl-c"><span class="pl-c">#</span> ignore SettingWithCopy here in case the user mutates</span>
    <span class="pl-c1">883</span>         <span class="pl-k">with</span> option_context(<span class="pl-s"><span class="pl-pds">'</span>mode.chained_assignment<span class="pl-pds">'</span></span>, <span class="pl-c1">None</span>):
--&gt; 884             return self._python_apply_general(f)
    <span class="pl-c1">885</span>
    <span class="pl-c1">886</span>     <span class="pl-k">def</span> <span class="pl-en">_python_apply_general</span>(<span class="pl-smi"><span class="pl-smi">self</span></span>, <span class="pl-smi">f</span>):

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in _python_apply_general(self, f)
    <span class="pl-c1">891</span>             keys,
    <span class="pl-c1">892</span>             values,
--&gt; 893             not_indexed_same=mutated or self.mutated)
    <span class="pl-c1">894</span>
    <span class="pl-c1">895</span>     <span class="pl-k">def</span> <span class="pl-en">_iterate_slices</span>(<span class="pl-smi"><span class="pl-smi">self</span></span>):

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in _wrap_applied_output(self, keys, values, not_indexed_same)
   3920         elif isinstance(v, DataFrame):
   3921             return self._concat_objects(keys, values,
-&gt; 3922                                         not_indexed_same=not_indexed_same)
   3923         elif self.grouper.groupings is not None:
   3924             if len(self.grouper.groupings) &gt; 1:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/groupby.py in _concat_objects(self, keys, values, not_indexed_same)
   1085                     result = result.take(indexer, axis=self.axis)
   1086                 else:
-&gt; 1087                     result = result.reindex(ax, axis=self.axis)
   1088
   1089         elif self.group_keys:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    <span class="pl-c1">145</span>         <span class="pl-k">@</span>wraps(func)
    <span class="pl-c1">146</span>         <span class="pl-k">def</span> <span class="pl-en">wrapper</span>(<span class="pl-k">*</span><span class="pl-smi">args</span>, <span class="pl-k">**</span><span class="pl-smi">kwargs</span>):
--&gt; 147             return func(*args, **kwargs)
    <span class="pl-c1">148</span>
    <span class="pl-c1">149</span>         <span class="pl-k">if</span> <span class="pl-k">not</span> <span class="pl-c1">PY2</span>:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/frame.py in reindex(self, *args, **kwargs)
   2979         kwargs.pop('axis', None)
   2980         kwargs.pop('labels', None)
-&gt; 2981         return super(DataFrame, self).reindex(**kwargs)
   2982
   2983     @Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/generic.py in reindex(self, *args, **kwargs)
   3356         # perform the reindex on the axes
   3357         return self._reindex_axes(axes, level, limit, tolerance, method,
-&gt; 3358                                   fill_value, copy).__finalize__(self)
   3359
   3360     def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/frame.py in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
   2909         if columns is not None:
   2910             frame = frame._reindex_columns(columns, method, copy, level,
-&gt; 2911                                            fill_value, limit, tolerance)
   2912
   2913         index = axes['index']

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/frame.py in _reindex_columns(self, new_columns, method, copy, level, fill_value, limit, tolerance)
   2934         return self._reindex_with_indexers({1: [new_columns, indexer]},
   2935                                            copy=copy, fill_value=fill_value,
-&gt; 2936                                            allow_dups=False)
   2937
   2938     def _reindex_multi(self, axes, copy, fill_value):

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/generic.py in _reindex_with_indexers(self, reindexers, fill_value, copy, allow_dups)
   3477                                                 fill_value=fill_value,
   3478                                                 allow_dups=allow_dups,
-&gt; 3479                                                 copy=copy)
   3480
   3481         if copy and new_data is self._data:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/internals.py in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups, copy)
   4125         # some axes don't allow reindexing with dups
   4126         if not allow_dups:
-&gt; 4127             self.axes[axis]._can_reindex(indexer)
   4128
   4129         if axis &gt;= self.ndim:

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/indexes/base.py in _can_reindex(self, indexer)
   2940         # trying to reindex on an axis with duplicates
   2941         if not self.is_unique and len(indexer):
-&gt; 2942             raise ValueError("cannot reindex from a duplicate axis")
   2943
   2944     def reindex(self, target, method=None, level=None, limit=None,

<span class="pl-en">ValueError</span>: <span class="pl-s">cannot reindex from a duplicate axis</span></pre></div>
</details>