title: Create nested dictionary
body: <p>I have a <code>DataFrame</code> that looks like the 3 columns here:</p>
  
  <pre><code>Automated test case name    TC Type     Module Name
          name 1              Pre-Req      Module 1
          name 2              Pre-Req      Module 1
          name 3              Pre-Req      Module 1
          name 4              Pre-Req      Module 1
          name 5              Actual       Module 1
          name 6              Actual       Module 1
          name 7              Pre-Req      Module 2
          name 8              Actual       Module 2
  </code></pre>
  
  <p>What I have done is: if <code>"Actual"</code> word is found in the column <code>'TC Type'</code>, then add all the previous <code>"Pre-Req"</code> with all <code>"Actual"</code>; if I find <code>"Actual"</code> consecutively, I need to take all the <code>"Pre-Req"</code> before the two <code>"Actual"</code>.</p>
  
  <p>The code:</p>
  
  <pre><code>new_list = []
  df = data_TC1
  Dict_TestCase_Mapping = {}
  is_ActualFound = False
  for i in range(1, len(df)):
      if "Actual" == df['TC Type'][i]:
          Dict_TestCase_Mapping[df['Automated test case name'][i]] = [i, new_list]
          is_ActualFound = True
      elif is_ActualFound and df['TC Type'][i] != "Actual":
          new_list = []
          new_list.append(df['Automated test case name'][i])
          is_ActualFound = False
      else:
          new_list.append(df['Automated test case name'][i])
  </code></pre>
  
  <p>Current output:</p>
  
  <pre><code>{
      name 5: [4, [name 1,
          name 2,
          name 3,
          name 4
      ]],
      name 6: [5, [name 1,
          name 2,
          name 3,
          name 4
      ]],
      name 8: [7, [name 7]]
  }
  </code></pre>
  
  <p>What I want is <code>Module Name</code> as the key of the above dictonary.</p>
  
  <p>Expected output:</p>
  
  <pre><code>{
      Module 1: {
          name 5: [4, [name 1,
              name 2,
              name 3,
              name 4
          ]],
          name 6: [5, [name 1,
              name 2,
              name 3,
              name 4
          ]]
      },
      Module 2: {
          name 8: [7, [name 7]]
      }
  }
  </code></pre>
  
  <p>How do I achieve this output? Any help received will be appreciated.</p>