<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="df = pd.DataFrame({'First': ['A', 'A', 'A', 'B', 'B'], 'Last': ['C', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
df.set_index(['Last','First'], inplace=True)

# rename1
df.rename(index={('C','A'):('C','NEWFIRST')})

# rename2
df.rename(index={('C','A'):('NEWLAST','A')})"><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">'First'</span>: [<span class="pl-s">'A'</span>, <span class="pl-s">'A'</span>, <span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>, <span class="pl-s">'B'</span>], <span class="pl-s">'Last'</span>: [<span class="pl-s">'C'</span>, <span class="pl-s">'D'</span>, <span class="pl-s">'E'</span>, <span class="pl-s">'E'</span>, <span class="pl-s">'F'</span>], <span class="pl-s">'C'</span>:[<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>]})
<span class="pl-s1">df</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'Last'</span>,<span class="pl-s">'First'</span>], <span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-c"># rename1</span>
<span class="pl-s1">df</span>.<span class="pl-en">rename</span>(<span class="pl-s1">index</span><span class="pl-c1">=</span>{(<span class="pl-s">'C'</span>,<span class="pl-s">'A'</span>):(<span class="pl-s">'C'</span>,<span class="pl-s">'NEWFIRST'</span>)})

<span class="pl-c"># rename2</span>
<span class="pl-s1">df</span>.<span class="pl-en">rename</span>(<span class="pl-s1">index</span><span class="pl-c1">=</span>{(<span class="pl-s">'C'</span>,<span class="pl-s">'A'</span>):(<span class="pl-s">'NEWLAST'</span>,<span class="pl-s">'A'</span>)})</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Renaming Muiltiindex values does nothing, not even raise an Exception.</p>
<h4 dir="auto">Expected Output</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rename1 = pd.DataFrame({'First': ['NEWFIRST', 'A', 'A', 'B', 'B'], 'Last': ['C', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename1.set_index(['Last','First'], inplace=True)

rename2 = pd.DataFrame({'First': ['A', 'A', 'A', 'B', 'B'], 'Last': ['NEWLAST', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename2.set_index(['Last','First'], inplace=True)"><pre class="notranslate"><code class="notranslate">rename1 = pd.DataFrame({'First': ['NEWFIRST', 'A', 'A', 'B', 'B'], 'Last': ['C', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename1.set_index(['Last','First'], inplace=True)

rename2 = pd.DataFrame({'First': ['A', 'A', 'A', 'B', 'B'], 'Last': ['NEWLAST', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename2.set_index(['Last','First'], inplace=True)
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
```
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.8.0-46-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_AU.UTF-8
LOCALE: en_AU.UTF-8
<p dir="auto">pandas: 0.19.2+0.g825876c.dirty<br>
nose: 1.3.7<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.11.2<br>
scipy: 0.18.1<br>
statsmodels: 0.6.1<br>
xarray: None<br>
IPython: 5.1.0<br>
sphinx: 1.5.1<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: 1.1.0<br>
tables: 3.3.0<br>
numexpr: 2.6.1<br>
matplotlib: 1.5.3<br>
openpyxl: 2.4.0<br>
xlrd: 1.0.0<br>
xlwt: 1.1.2<br>
xlsxwriter: 0.9.6<br>
lxml: None<br>
bs4: 4.5.1<br>
html5lib: None<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: 1.1.4<br>
pymysql: None<br>
psycopg2: 2.6.2 (dt dec pq3 ext lo64)<br>
jinja2: 2.8<br>
boto: 2.45.0<br>
pandas_datareader: None</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;/details&gt;"><pre class="notranslate"><code class="notranslate">&lt;/details&gt;
</code></pre></div></details>
<p dir="auto">There appears to be an issue with Excel writers when DataFrame column names are duplicated. This issue that was initially reported on <a href="http://stackoverflow.com/questions/19363779/problems-writing-to-file-in-pandas" rel="nofollow">StackOverflow</a>.</p>
<p dir="auto">For example consider the following program:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
from pandas import DataFrame

df = DataFrame([[1, 2, 3], [1, 2, 3], [1, 2, 3]])

df.columns = ['A', 'B', 'B']  # !!!

df.to_csv('output.csv')
df.to_excel('output.xlsx')
"><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">from</span> <span class="pl-s1">pandas</span> <span class="pl-k">import</span> <span class="pl-v">DataFrame</span>

<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-v">DataFrame</span>([[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>]])

<span class="pl-s1">df</span>.<span class="pl-s1">columns</span> <span class="pl-c1">=</span> [<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>, <span class="pl-s">'B'</span>]  <span class="pl-c"># !!!</span>

<span class="pl-s1">df</span>.<span class="pl-en">to_csv</span>(<span class="pl-s">'output.csv'</span>)
<span class="pl-s1">df</span>.<span class="pl-en">to_excel</span>(<span class="pl-s">'output.xlsx'</span>)</pre></div>
<p dir="auto">Note the duplicated column name. The <code class="notranslate">df</code> for this looks like this:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; df
   A  B  B
0  1  2  3
1  1  2  3
2  1  2  3"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>
   <span class="pl-v">A</span>  <span class="pl-v">B</span>  <span class="pl-v">B</span>
<span class="pl-c1">0</span>  <span class="pl-c1">1</span>  <span class="pl-c1">2</span>  <span class="pl-c1">3</span>
<span class="pl-c1">1</span>  <span class="pl-c1">1</span>  <span class="pl-c1">2</span>  <span class="pl-c1">3</span>
<span class="pl-c1">2</span>  <span class="pl-c1">1</span>  <span class="pl-c1">2</span>  <span class="pl-c1">3</span></pre></div>
<p dir="auto">The corresponding output of the CSV is as expected:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cat output.csv
,A,B,B
0,1,2,3
1,1,2,3
2,1,2,3"><pre class="notranslate"><code class="notranslate">$ cat output.csv
,A,B,B
0,1,2,3
1,1,2,3
2,1,2,3
</code></pre></div>
<p dir="auto">However, the output of the any of the Excel writers is incorrect:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/049e43e77c0a2068e6d0715599e969de9e89f695ffcaed63477891aaaabe37ad/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f39343236372f313333383334372f62343238303361322d333565352d313165332d393132652d3439323364333338326633642e706e67"><img src="https://camo.githubusercontent.com/049e43e77c0a2068e6d0715599e969de9e89f695ffcaed63477891aaaabe37ad/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f39343236372f313333383334372f62343238303361322d333565352d313165332d393132652d3439323364333338326633642e706e67" alt="screenshot" data-canonical-src="https://f.cloud.github.com/assets/94267/1338347/b42803a2-35e5-11e3-912e-4923d3382f3d.png" style="max-width: 100%;"></a></p>
<p dir="auto">The issue appears to be in <code class="notranslate">pandas/core/format.py</code>. The output data is gathered based on column names, as shown below, which causes issues with duplicate names.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    def _format_regular_rows(self):
        ...
        for colidx, colname in enumerate(self.columns):
            series = self.df[colname]
            ... "><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">_format_regular_rows</span>(<span class="pl-s1">self</span>):
        ...
        <span class="pl-k">for</span> <span class="pl-s1">colidx</span>, <span class="pl-s1">colname</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(<span class="pl-s1">self</span>.<span class="pl-s1">columns</span>):
            <span class="pl-s1">series</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">df</span>[<span class="pl-s1">colname</span>]
            ... </pre></div>
<p dir="auto">I initially thought that this might be the correct behaviour and that column names shouldn't be duplicated but given that the output is different to the csv writer it looks like a bug.</p>
<p dir="auto">I'll write a test case but I'm not sure of the best way to fix the issue.</p>