<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="# Building Dataframe (reused from example, the fact that it uses datetime and numpy is probably not that important) 
date_range = pd.date_range(start=dt.datetime(2017,1,1), end=dt.datetime(2020,12,31), freq='W')
to_concat = []
for val in range(1,5):
    frame_tmp = pd.DataFrame()
    frame_tmp['DT'] = date_range
    frame_tmp['type'] = val
    frame_tmp['value'] = np.random.randint(1, 6, frame_tmp.shape[0])
    to_concat.append(frame_tmp)

df = pd.concat(to_concat, ignore_index=True)

# Does not work under pandas 0.23.0 and 0.23.1 worked in 0.22 and for some versions before
df.set_index('DT').groupby(level=0)['value'].expanding().mean()

# Workaround not setting as index is fine
df.groupby(['DT'])['value'].expanding().mean()
"><pre class="notranslate"><span class="pl-c"># Building Dataframe (reused from example, the fact that it uses datetime and numpy is probably not that important) </span>
<span class="pl-s1">date_range</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s1">start</span><span class="pl-c1">=</span><span class="pl-s1">dt</span>.<span class="pl-en">datetime</span>(<span class="pl-c1">2017</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>), <span class="pl-s1">end</span><span class="pl-c1">=</span><span class="pl-s1">dt</span>.<span class="pl-en">datetime</span>(<span class="pl-c1">2020</span>,<span class="pl-c1">12</span>,<span class="pl-c1">31</span>), <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'W'</span>)
<span class="pl-s1">to_concat</span> <span class="pl-c1">=</span> []
<span class="pl-k">for</span> <span class="pl-s1">val</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">1</span>,<span class="pl-c1">5</span>):
    <span class="pl-s1">frame_tmp</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>()
    <span class="pl-s1">frame_tmp</span>[<span class="pl-s">'DT'</span>] <span class="pl-c1">=</span> <span class="pl-s1">date_range</span>
    <span class="pl-s1">frame_tmp</span>[<span class="pl-s">'type'</span>] <span class="pl-c1">=</span> <span class="pl-s1">val</span>
    <span class="pl-s1">frame_tmp</span>[<span class="pl-s">'value'</span>] <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">randint</span>(<span class="pl-c1">1</span>, <span class="pl-c1">6</span>, <span class="pl-s1">frame_tmp</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>])
    <span class="pl-s1">to_concat</span>.<span class="pl-en">append</span>(<span class="pl-s1">frame_tmp</span>)

<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>(<span class="pl-s1">to_concat</span>, <span class="pl-s1">ignore_index</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-c"># Does not work under pandas 0.23.0 and 0.23.1 worked in 0.22 and for some versions before</span>
<span class="pl-s1">df</span>.<span class="pl-en">set_index</span>(<span class="pl-s">'DT'</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-s">'value'</span>].<span class="pl-en">expanding</span>().<span class="pl-en">mean</span>()

<span class="pl-c"># Workaround not setting as index is fine</span>
<span class="pl-s1">df</span>.<span class="pl-en">groupby</span>([<span class="pl-s">'DT'</span>])[<span class="pl-s">'value'</span>].<span class="pl-en">expanding</span>().<span class="pl-en">mean</span>()</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">When using expanding().mean() in a groupby on index as in the above code, pandas 0.23.1 and 0.23.0 produce an error:<br>
ValueError: Duplicated level name: "DT", assigned to level 1, is already used for level 0.</p>
<p dir="auto">Previous version would insert another level with the same name. So it is probably linked with a change in error being thrown.</p>
<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: 3.6.6.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.13.0-45-generic<br>
machine: x86_64<br>
processor: x86_64<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_US.UTF-8<br>
LOCALE: en_US.UTF-8</p>
<p dir="auto">pandas: 0.23.1<br>
pytest: None<br>
pip: 10.0.1<br>
setuptools: 39.2.0<br>
Cython: None<br>
numpy: 1.14.5<br>
scipy: None<br>
pyarrow: None<br>
xarray: None<br>
IPython: 6.4.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.7.3<br>
pytz: 2018.5<br>
blosc: None<br>
bottleneck: None<br>
tables: 3.4.4<br>
numexpr: 2.6.5<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: 1.0.1<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.10<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">Hi,<br>
I updated to version 0.23.0 and all of a sudden the following code breaks:</p>
<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(data={'date': list(pd.date_range('5.1.2018', '5.10.2018')),
                        'vals': list(range(10))})
df.groupby([df.date.dt.month, df.date.dt.day])['vals'].sum()

ValueError: Duplicated level name: &quot;date&quot;, assigned to level 1, is already used for level 0."><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-s1">data</span><span class="pl-c1">=</span>{<span class="pl-s">'date'</span>: <span class="pl-en">list</span>(<span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'5.1.2018'</span>, <span class="pl-s">'5.10.2018'</span>)),
                        <span class="pl-s">'vals'</span>: <span class="pl-en">list</span>(<span class="pl-en">range</span>(<span class="pl-c1">10</span>))})
<span class="pl-s1">df</span>.<span class="pl-en">groupby</span>([<span class="pl-s1">df</span>.<span class="pl-s1">date</span>.<span class="pl-s1">dt</span>.<span class="pl-s1">month</span>, <span class="pl-s1">df</span>.<span class="pl-s1">date</span>.<span class="pl-s1">dt</span>.<span class="pl-s1">day</span>])[<span class="pl-s">'vals'</span>].<span class="pl-en">sum</span>()

<span class="pl-v">ValueError</span>: <span class="pl-v">Duplicated</span> <span class="pl-s1">level</span> <span class="pl-s1">name</span>: <span class="pl-s">"date"</span>, <span class="pl-s1">assigned</span> <span class="pl-s1">to</span> <span class="pl-s1">level</span> <span class="pl-c1">1</span>, <span class="pl-c1">is</span> <span class="pl-s1">already</span> <span class="pl-s1">used</span> <span class="pl-k">for</span> <span class="pl-s1">level</span> <span class="pl-c1">0.</span></pre></div>
<h3 dir="auto">Expected output:</h3>
<p dir="auto">Using version 0.22.0 the same code yields the following:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="date  date
5     1       0
      2       1
      3       2
      4       3
      5       4
      6       5
      7       6
      8       7
      9       8
      10      9
Name: vals, dtype: int64"><pre class="notranslate"><span class="pl-s1">date</span>  <span class="pl-s1">date</span>
<span class="pl-c1">5</span>     <span class="pl-c1">1</span>       <span class="pl-c1">0</span>
      <span class="pl-c1">2</span>       <span class="pl-c1">1</span>
      <span class="pl-c1">3</span>       <span class="pl-c1">2</span>
      <span class="pl-c1">4</span>       <span class="pl-c1">3</span>
      <span class="pl-c1">5</span>       <span class="pl-c1">4</span>
      <span class="pl-c1">6</span>       <span class="pl-c1">5</span>
      <span class="pl-c1">7</span>       <span class="pl-c1">6</span>
      <span class="pl-c1">8</span>       <span class="pl-c1">7</span>
      <span class="pl-c1">9</span>       <span class="pl-c1">8</span>
      <span class="pl-c1">10</span>      <span class="pl-c1">9</span>
<span class="pl-v">Name</span>: <span class="pl-s1">vals</span>, <span class="pl-s1">dtype</span>: <span class="pl-s1">int64</span></pre></div>
<p dir="auto">It obviously contains duplicated level names. I get why this might be a problem, but as of version 0.23.0 it's not possible to specify the resulting level names.</p>