title: KeyError: 'Requested level (date) does not match index name (None)'
body: <p>I got error while reshaping my dataframe data.</p>
  <pre><code>KeyError: 'Requested level (date) does not match index name (None)'
  </code></pre>
  <p>More details are as below:</p>
  <pre><code># dataframe
  
  # print(df.head(3))
         
      
  ...
  account_id    entity     ae     is_pc   is_new_customer agency  related_entity  type    medium   our_side_entity      settlement_title  settlement_short_title  settlement_type  system_value   account_status  date    sale
  12323         entity1   ae1     PC        yes            MB                     EC     TWITTER   our_side_entity1    settlement_title   settlement_short_title      1                0.2          active    2020-07-01     jimmy 
  12323         entity1   ae1     PC        yes            MB                     EC     GOOGLE    our_side_entity2    settlement_title   settlement_short_title      1                0.5          active    2020-07-02    jimmy
  1037093       Bentity1  ae1     PC        yes            MB                     APP    Google    our_side_entity3    settlement_title   settlement_short_title      2                0            disable   2020-07-03     jimmy
  1037093       Bentity1  ae1     PC        yes            MB                     APP    Google    our_side_entity3    settlement_title   settlement_short_title      2                                      2020-07-04     jimmy
  1037093       Bentity1  ae1     PC        yes            MB                     APP    Google    our_side_entity3    settlement_title   settlement_short_title      2                                      2020-07-05      jimmy
  ...  
  
  </code></pre>
  <p>Then I want group by <code>account, date</code> and sum the total system_value of the account.
  I tried with below codes but failed:</p>
  <pre><code>
              indices = OrderedDict([
                  ('account_id', 'ID'),
                  ('entity', 'entity'),
                  ('ae', 'AE'),
                  ('is_pc', 'PC'),
                  ('is_new_customer', 'new_customer'),
                  ('agency', 'agency'),
                  ('related_entity', 'related_entity'),
                  ('type', 'type'),
                  ('medium', 'medium'),
                  ('our_side_entity', 'our_side_entity'),
                  ('settlement_title', 'settlement_title'),
                  ('settlement_short_title', 'settlement_short_title'),
                  ('settlement_type', 'settlement_type'),
                  ('account_status', 'account_status'),
                  ('sale', 'sale'),
                  ('date', 'date'),
  
              ])
  
  
              df = df.groupby(list(indices.keys())).system_value.sum() \
                  .unstack('date', fill_value=None) \
                  .assign(total=lambda x: x.sum(1)) \
                  .reset_index()
              print(df)
              df = df.rename(columns=indices). \
                  set_index(indices['account_id'])
  
  </code></pre>
  <p>error like below:</p>
  <pre><code>KeyError: 'Requested level (date) does not match index name (None)'
  
  </code></pre>
  <p>Could you please tell me what's wrong with my trial?</p>
  <p>Thanks.</p>
  <blockquote>
  <p>Update more details of my trial</p>
  </blockquote>
  <p>Below codes can reproduce the error all the time</p>
  <pre><code>import pandas as pd
  from collections import OrderedDict
  
  
  s = [
      {'account_id': '123123213',
       'entity': 'entity2',
       'ae': 'ae1',
       'is_pc': 'PC',
       'is_new_customer': 'yes',
       'agency': 'BV',
       'related_entity': None,
       'type': 'EC',
       'medium': 'Facebook',
       'our_side_entity': 'our_side_entity',
       'settlement_title': 'settlement_title',
       'settlement_short_title': 'SS',
       'settlement_type': 'unknown',
       'system_value': None,
       'account_status': None,
       'date': '2020-07-22',
       'sale': 'sale1'},
  ]
  
  
  indices = OrderedDict([
      ('account_id', 'ID'),
      ('entity', 'Entity'),
      ('ae', 'AE'),
      ('is_pc', 'PC'),
      ('is_new_customer', 'NEW_CUSTOMER'),
      ('agency', 'agency'),
      ('related_entity', 'related_entity'),
      ('type', 'type'),
      ('medium', 'medium'),
      ('our_side_entity', 'our_side_entity'),
      ('settlement_title', 'settlement_title'),
      ('settlement_short_title', 'settlement_short_title'),
      ('settlement_type', 'settlement_type'),
      ('sale', 'sale'),
      ('date', 'date'),
  ])
  
  df = pd.DataFrame.from_records(s)
  # print df.to_dict()
  
  {'account_id': {0: '123123213'}, 'entity': {0: 'entity2'}, 'ae': {0: 'ae1'}, 'is_pc': {0: 'PC'}, 'is_new_customer': {0: 'yes'}, 'agency': {0: 'BV'}, 'related_entity': {0: None}, 'type': {0: 'EC'}, 'medium': {0: 'Facebook'}, 'our_side_entity': {0: 'our_side_entity'}, 'settlement_title': {0: 'settlement_title'}, 'settlement_short_title': {0: 'SS'}, 'settlement_type': {0: 'unknown'}, 'system_value': {0: None}, 'account_status': {0: None}, 'date': {0: '2020-07-22'}, 'sale': {0: 'sale1'}}
  
  df = df.groupby(list(indices.keys())).system_value.sum() \
      .unstack('date', fill_value=None) \
      .assign(total=lambda x: x.sum(1)) \
      .reset_index()
  indices[&quot;account_status&quot;] = &quot;status&quot;
  df = df.rename(columns=indices). \
      set_index(indices['account_id'])
  print(df)
  
  
  
  </code></pre>