<p dir="auto">Only happens when the user function mutates the input</p>
<p dir="auto">Originally from: <a href="http://stackoverflow.com/questions/20691168/pandas-apply-to-data-frame-groupby/20705226#20705226" rel="nofollow">http://stackoverflow.com/questions/20691168/pandas-apply-to-data-frame-groupby/20705226#20705226</a></p>
<p dir="auto">Could be auto-fixed or maybe just a better error report to the user (about the dups)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [40]: df = DataFrame(dict(A = ['foo','foo','bar','bar'], B = np.random.randn(4)),index=[1,1,2,2])

In [41]: df
Out[41]: 
     A         B
1  foo  0.971425
1  foo -1.151693
2  bar  1.265031
2  bar -0.219011

[4 rows x 2 columns]

In [42]: def f(x):                                                
    x['std'] = x['B'].std()
    return x
   ....: "><pre class="notranslate"><code class="notranslate">In [40]: df = DataFrame(dict(A = ['foo','foo','bar','bar'], B = np.random.randn(4)),index=[1,1,2,2])

In [41]: df
Out[41]: 
     A         B
1  foo  0.971425
1  foo -1.151693
2  bar  1.265031
2  bar -0.219011

[4 rows x 2 columns]

In [42]: def f(x):                                                
    x['std'] = x['B'].std()
    return x
   ....: 
</code></pre></div>
<p dir="auto">Cannot straight perform the apply</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [44]: df.groupby('A').apply(f)
ValueError: cannot reindex from a duplicate axis"><pre class="notranslate"><code class="notranslate">In [44]: df.groupby('A').apply(f)
ValueError: cannot reindex from a duplicate axis
</code></pre></div>
<p dir="auto">By using unique indices everything is ok (so straightforward to fix)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [45]: df.reset_index().groupby('A').apply(f).set_index('index')
Out[45]: 
         A         B       std
index                         
1      foo  0.971425  1.501271
1      foo -1.151693  1.501271
2      bar  1.265031  1.049376
2      bar -0.219011  1.049376

[4 rows x 3 columns]"><pre class="notranslate"><code class="notranslate">In [45]: df.reset_index().groupby('A').apply(f).set_index('index')
Out[45]: 
         A         B       std
index                         
1      foo  0.971425  1.501271
1      foo -1.151693  1.501271
2      bar  1.265031  1.049376
2      bar -0.219011  1.049376

[4 rows x 3 columns]
</code></pre></div>
<p dir="auto">Me and several of my colleagues typically create output for variables that have greek letters. Inside pandas, we then call them "epsilon", "sBar" or similar. Right now we have to run a string replace on the output of to_latex() and then manually save it to a file.</p>
<p dir="auto">It'd be nice to be able to give to_latex() a template such as ['epsilon':'$\epsilon$', 'sBar':'$\bar s$'] and then to_latex() would replace these in the output accordingly.</p>