<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="# Your code here
"><pre class="notranslate"><span class="pl-c"># Your code here</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">[this should explain <strong>why</strong> the current behaviour is a problem and why the expected output is a better solution.]</p>
<p dir="auto"><strong>Note</strong>: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!</p>
<p dir="auto"><strong>Note</strong>: Many problems can be resolved by simply upgrading <code class="notranslate">pandas</code> to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if <code class="notranslate">master</code> addresses this issue, but that is not necessary.</p>
<p dir="auto">For documentation-related issues, you can check the latest versions of the docs on <code class="notranslate">master</code> here:</p>
<p dir="auto"><a href="https://pandas-docs.github.io/pandas-docs-travis/" rel="nofollow">https://pandas-docs.github.io/pandas-docs-travis/</a></p>
<p dir="auto">If the issue has not been resolved there, go ahead and file it in the issue tracker.</p>
<h4 dir="auto">Expected Output</h4>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<p dir="auto">[paste the output of <code class="notranslate">pd.show_versions()</code> here below this line]</p>
</details>
<h4 dir="auto">Here's my code</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import pandas as pd
from numpy.random import randn

az = pd.DataFrame({
    'A' : ['a1', 'a1', 'a2', 'a3']
  , 'B' : ['b1', 'b2', 'b3', 'b4']
  , 'Vals' : randn(4)
}).groupby(['A', 'B']).sum()

def add_zero(row) :
    name = row.name
    row.loc[name,'b0'] = 0
    return row

az['Vals'].groupby(level='A').apply(lambda s : add_zero(s))

&gt;&gt;&gt; A   A   B 
&gt;&gt;&gt; a1  a1  b1    1.238985
&gt;&gt;&gt;         b2    0.686438
&gt;&gt;&gt;         b0    0.000000
&gt;&gt;&gt; a2  a2  b3   -0.503039
&gt;&gt;&gt;         b0    0.000000
&gt;&gt;&gt; a3  a3  b4   -0.083150
&gt;&gt;&gt;         b0    0.000000
&gt;&gt;&gt; Name: Vals, dtype: float64"><pre class="notranslate"><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-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">numpy</span>.<span class="pl-s1">random</span> <span class="pl-k">import</span> <span class="pl-s1">randn</span>

<span class="pl-s1">az</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({
    <span class="pl-s">'A'</span> : [<span class="pl-s">'a1'</span>, <span class="pl-s">'a1'</span>, <span class="pl-s">'a2'</span>, <span class="pl-s">'a3'</span>]
  , <span class="pl-s">'B'</span> : [<span class="pl-s">'b1'</span>, <span class="pl-s">'b2'</span>, <span class="pl-s">'b3'</span>, <span class="pl-s">'b4'</span>]
  , <span class="pl-s">'Vals'</span> : <span class="pl-en">randn</span>(<span class="pl-c1">4</span>)
}).<span class="pl-en">groupby</span>([<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>]).<span class="pl-en">sum</span>()

<span class="pl-k">def</span> <span class="pl-en">add_zero</span>(<span class="pl-s1">row</span>) :
    <span class="pl-s1">name</span> <span class="pl-c1">=</span> <span class="pl-s1">row</span>.<span class="pl-s1">name</span>
    <span class="pl-s1">row</span>.<span class="pl-s1">loc</span>[<span class="pl-s1">name</span>,<span class="pl-s">'b0'</span>] <span class="pl-c1">=</span> <span class="pl-c1">0</span>
    <span class="pl-k">return</span> <span class="pl-s1">row</span>

<span class="pl-s1">az</span>[<span class="pl-s">'Vals'</span>].<span class="pl-en">groupby</span>(<span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-s">'A'</span>).<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">s</span> : <span class="pl-en">add_zero</span>(<span class="pl-s1">s</span>))

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-v">A</span>   <span class="pl-v">A</span>   <span class="pl-v">B</span> 
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a1</span>  <span class="pl-s1">a1</span>  <span class="pl-s1">b1</span>    <span class="pl-c1">1.238985</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>         <span class="pl-s1">b2</span>    <span class="pl-c1">0.686438</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>         <span class="pl-s1">b0</span>    <span class="pl-c1">0.000000</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a2</span>  <span class="pl-s1">a2</span>  <span class="pl-s1">b3</span>   <span class="pl-c1">-</span><span class="pl-c1">0.503039</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>         <span class="pl-s1">b0</span>    <span class="pl-c1">0.000000</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a3</span>  <span class="pl-s1">a3</span>  <span class="pl-s1">b4</span>   <span class="pl-c1">-</span><span class="pl-c1">0.083150</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>         <span class="pl-s1">b0</span>    <span class="pl-c1">0.000000</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-v">Name</span>: <span class="pl-v">Vals</span>, <span class="pl-s1">dtype</span>: <span class="pl-s1">float64</span></pre></div>
<h4 dir="auto">Expected Output</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; A   B 
&gt;&gt;&gt; a1  b1    1.238985
&gt;&gt;&gt;     b2    0.686438
&gt;&gt;&gt;     b0    0.000000
&gt;&gt;&gt; a2  b3   -0.503039
&gt;&gt;&gt;     b0    0.000000
&gt;&gt;&gt; a3  b4   -0.083150
&gt;&gt;&gt;     b0    0.000000
&gt;&gt;&gt; Name: Vals, dtype: float64"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-v">A</span>   <span class="pl-v">B</span> 
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a1</span>  <span class="pl-s1">b1</span>    <span class="pl-c1">1.238985</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>     <span class="pl-s1">b2</span>    <span class="pl-c1">0.686438</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>     <span class="pl-s1">b0</span>    <span class="pl-c1">0.000000</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a2</span>  <span class="pl-s1">b3</span>   <span class="pl-c1">-</span><span class="pl-c1">0.503039</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>     <span class="pl-s1">b0</span>    <span class="pl-c1">0.000000</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a3</span>  <span class="pl-s1">b4</span>   <span class="pl-c1">-</span><span class="pl-c1">0.083150</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span>     <span class="pl-s1">b0</span>    <span class="pl-c1">0.000000</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-v">Name</span>: <span class="pl-v">Vals</span>, <span class="pl-s1">dtype</span>: <span class="pl-s1">float64</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">I would like to add rows with new index in a grouped by Dataframe, it seems to work, yet it duplicates an index/level column, and I can't figure why it does.<br>
Is there any way around ?</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
<p dir="auto">pandas: 0.19.2<br>
nose: 1.3.7<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.11.3<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.2.0<br>
tables: 3.2.2<br>
numexpr: 2.6.1<br>
matplotlib: 2.0.0<br>
openpyxl: 2.4.1<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.2<br>
bs4: 4.5.3<br>
html5lib: None<br>
httplib2: 0.10.3<br>
apiclient: 1.6.2<br>
sqlalchemy: 1.1.5<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.4<br>
boto: 2.45.0<br>
pandas_datareader: None</p>
</details>