title: Python Pandas Groupby with 'Subtotal' values in output?
body: <p>I am really new to python and was having some difficulty simplifying my steps to create a 'subtotal value' when using pandas groupby function on Source dataframe ['Product', 'Customer']. </p>
  
  <p>Please help offer any pointers and solutions. Thank you!</p>
  
  <pre><code># Desired Output
  Product Customer    Qty
  Item A  Cust1       5
          Cust4       10
          Subtotal    15
  Item B  Cust1       15
          Cust2       5
          Cust6       1
          Subtotal    21
  Item C  Cust3       1
          Subtotal    1
  
  # Source Dataframe
      Product Customer  Qty
  0   Item A  Cust1     5
  1   Item A  Cust4     10
  2   Item B  Cust1     15
  3   Item B  Cust2     5
  4   Item B  Cust6     1
  5   Item C  Cust3     1
  
  # Source Dataframe code
  source_df = pd.DataFrame({
      'Product'  : ['Item A', 'Item A', 'Item B', 'Item B','Item B', 'Item C'],
      'Customer' : ['Cust1', 'Cust4', 'Cust1', 'Cust2', 'Cust6', 'Cust3'],
      'Qty'      : [5,10,15,5,1,1]
  })
  </code></pre>
  
  <p>My own solution: </p>
  
  <ol>
  <li>Create an intermediate dataframe groupby 'Product' and aggregate 'Qty' with a column filled with 'Subtotal' string values</li>
  <li>Concatenate Source dataframe and Intermediate dataframe</li>
  <li>Perform groupby once again on ['Product', 'Customer'] to get Desired Output</li>
  </ol>
  
  <p>It does not work if the Customer's name starts with a letter after 'S' because it may be sorted below 'Subtotal'. </p>
  
  <pre><code># Intermediate Subtotal Dataframe
      Product Customer    Qty
  0   Item A  Subtotal    15
  1   Item B  Subtotal    21
  2   Item C  Subtotal    1
  </code></pre>