title: How to Groupby a dataset on several columns and do different aggregation at the same time? Python
body: <p>I need to achieve several things:</p>
  <ul>
  <li><p>Group columns by Country and Products</p>
  </li>
  <li><p>Perform aggregation to get:</p>
  <pre><code> - percentage of my Products column for each country
   - Calculate the sum of columns Volume and Profit and UnrealizedProfit (2 columns 1st=Volume, 2nd= Profit + UnrealizedProfit)
  </code></pre>
  </li>
  <li><p>Display other columns as well</p>
  </li>
  </ul>
  <p>My DataFrame:</p>
  <pre><code>   Country       Sector       Products     Volume    Profit   UnrealizedProfit      
  0  Country_1     Sector1      Product_1     50         5            4
  1  Country_1     Sector2      Product_2     100        6            3
  2  Country_2     Sector1      Product_1     150        3            -1
  3  Country_2     Sector2      Product_2     200        -1           5
  4  Country_1     Sector1      Product_2     100        7            10
  5  Country_2     Sector2      Product_2     200        -3           -1
  6  Country_2     Sector1      Product_1     150        2            -1
  7  Country_1     Sector2      Product_1     50         5            -3
  </code></pre>
  <p>Note: I have a couple out thousand rows in my actual dataframe.</p>
  <p>Desired output would look like this:</p>
  <pre><code>   Country       Sector       Products     Product%   Volume    ExpectedProfit        
  0  Country_1     Sector1      Product_1     0.138      100        11
  1  Country_1     Sector2      Product_2     0.861      200        26
  2  Country_2     Sector1      Product_1     0.667      300        3
  3  Country_2     Sector2      Product_2     0.333      400        0
  </code></pre>
  <p>I only managed to do one aggregation at a time but not two.
  So far:</p>
  <pre><code>df = (data1.groupby('Country')['Products']
             .value_counts(normalize=True,sort=False)
             .reset_index(name='Product%'))
  print (df)
  </code></pre>
  <p>This code gives me:</p>
  <pre><code>   Country       Products     Product%
  0  Country 1     Product 1     0.138
  1  Country 1     Product 2     0.861
  2  Country 2     Product 1     0.667
  3  Country 2     Product 2     0.333
  </code></pre>
  <p>Each frequency of product is based on the related country --&gt; sum(Country1) =100%, sum(Country2)=100%...</p>
  <p>And for the Volume I manage to replicate it:</p>
  <pre><code>df = (data1.groupby(['Country','Product'])['Volume']
        .sum()
        .reset_index(name='Volume'))
  </code></pre>
  <p>I added the Product in the groupby() because I want to see the volume for each product and country.</p>
  <p>The Goal is to combine the Products% and Volume and adding the ExpectedProfit
  I don't know how to combine that and to do the aggregation for the profit, as mentioned (Profit+UnrealizedProfit)
  And as well displaying the Sector (I guess the sector could be included in the Groupby() since each the Sector has several products.</p>
  <p>Thank you for your help!</p>