<p dir="auto">Given a DataFrame which has a MultiIndex. When a label of the MultiIndex has the value NaN and the DataFrame is written to an excel file, the label will have a value which is not NaN in the excel file.</p>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="df = pd.DataFrame({'c1': [1,1,2,2],
                   'c2': [None] + &quot;b a b&quot;.split()})
df"><pre class="notranslate"><code class="notranslate">df = pd.DataFrame({'c1': [1,1,2,2],
                   'c2': [None] + "b a b".split()})
df
</code></pre></div>
<p dir="auto">returns a DataFrame where the first element of column 'c2' is NaN:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    c1  c2
0   1   
1   1   b
2   2   a
3   2   b"><pre class="notranslate"><code class="notranslate">    c1  c2
0   1   
1   1   b
2   2   a
3   2   b
</code></pre></div>
<p dir="auto">Set both columns as the index:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="df_midx = df.set_index(['c1', 'c2'])
df_midx"><pre class="notranslate"><code class="notranslate">df_midx = df.set_index(['c1', 'c2'])
df_midx
</code></pre></div>
<p dir="auto">returns</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="c1  c2
1   
1   b
2   a
2   b"><pre class="notranslate"><code class="notranslate">c1  c2
1   
1   b
2   a
2   b
</code></pre></div>
<p dir="auto">Write DataFrame to excel file and read it back in:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="df_midx.to_excel('df_midx.xlsx')
df_midx_from_xlsx = pd.read_excel('df_midx.xlsx')
df_midx_from_xlsx"><pre class="notranslate"><code class="notranslate">df_midx.to_excel('df_midx.xlsx')
df_midx_from_xlsx = pd.read_excel('df_midx.xlsx')
df_midx_from_xlsx
</code></pre></div>
<p dir="auto">returns</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    c1  c2
0   1.0 b
1       b
2   2.0 a
3       b"><pre class="notranslate"><code class="notranslate">    c1  c2
0   1.0 b
1       b
2   2.0 a
3       b
</code></pre></div>
<p dir="auto">The first element of column 'c2' is now set to 'b' instead of NaN.</p>
<h4 dir="auto">Expected Output</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    c1  c2
0   1.0
1       b
2   2.0 a
3       b"><pre class="notranslate"><code class="notranslate">    c1  c2
0   1.0
1       b
2   2.0 a
3       b
</code></pre></div>
<h4 dir="auto">output of <code class="notranslate">pd.show_versions()</code></h4>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: ac174349b0e1525475c2354e1c0b8ee1ed1cabad<br>
python: 2.7.6.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 3.13.0-88-generic<br>
machine: x86_64<br>
processor: x86_64<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_US.UTF-8</p>
<p dir="auto">pandas: 0.18.1<br>
nose: None<br>
pip: 1.5.4<br>
setuptools: 2.2<br>
Cython: None<br>
numpy: 1.11.0<br>
scipy: 0.16.1<br>
statsmodels: 0.6.1<br>
xarray: None<br>
IPython: 4.0.1<br>
sphinx: None<br>
patsy: 0.4.1<br>
dateutil: 2.5.3<br>
pytz: 2016.4<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: 2.5.2<br>
matplotlib: 1.5.0<br>
openpyxl: 2.3.5<br>
xlrd: 1.0.0<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8<br>
boto: None<br>
pandas_datareader: None</p>
<p dir="auto">This is related to the following commit.<br>
<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/jreback/pandas/commit/625ee94a31e4011b677785f12dfd204591cadfcf/hovercard" href="https://github.com/jreback/pandas/commit/625ee94a31e4011b677785f12dfd204591cadfcf">jreback@<tt>625ee94</tt></a></p>
<p dir="auto">When one level in the MultiIndex is all NaN, line 2819 in DataFrame.reset_index() and subfunction _maybe_cast, will have a problem, because values is empty.<br>
2819:    values = values.take(labels)<br>
IndexError: cannot do a non-empty take from an empty axes</p>
<p dir="auto">A possible fix is to add the following lines before 2819:<br>
if mask.all():<br>
values = labels * np.nan<br>
return values</p>