title: Sum and finding the largest number in pandas using pivot tables
body: <p>I got a project and want to know from more experienced users about the best way to reach the goal. Please, help a newbie)</p>
  <p>What is needed:</p>
  <ul>
  <li>Find the total value of the column “Metric Ton”</li>
  <li>Find the total value for each class in column “Class” (like: “HRW” – number, “HRS” – number, and etc.)</li>
  <li>Find the total value for each destination in column “Destination” (like: “Canada” - number, “China” – number, etc.)</li>
  </ul>
  <p>What I’m doing:</p>
  <ol>
  <li><p>Creating the dataFrame from bigger csv and filtering needed columns, so my frame looks like this:</p>
  <pre><code>inspections = pd.read_csv(&quot;CY2020.csv&quot;, usecols = [&quot;Thursday&quot;, &quot;Grade&quot;, &quot;Class&quot;, &quot;Grain&quot;, &quot;Destination&quot;, &quot;Metric Ton&quot; ], parse_dates = [&quot;Thursday&quot;])
  
  wheat = inspections[&quot;Grain&quot;].str.contains(&quot;WHEAT&quot;)
  
  current_week = inspections[&quot;Thursday&quot;] == &quot;2020-07-16&quot;
  
  weekly = inspections[wheat &amp; current_week]
  
  weekly.head(10)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/vqbti.png" rel="nofollow noreferrer">output</a></p>
  </li>
  <li><p>Creating  pivot table and finding out the total value of column “Metric Ton”:</p>
  <pre><code>piv = weekly.pivot_table(values = &quot;Metric Ton&quot;, index = [&quot;Destination&quot;], columns = &quot;Class&quot;, aggfunc = &quot;sum&quot;, fill_value = 0)
  piv.sum().sum()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/vqbti.png" rel="nofollow noreferrer">pivot_table</a></p>
  </li>
  <li><p>Finding out total values for each class and sorting them:</p>
  <pre><code>piv.sum().sort_values(ascending = False)
  </code></pre>
  </li>
  <li><p>Finding out total values for each destination and sorting them:</p>
  <pre><code>piv.sum(1).sort_values(ascending = False)
  </code></pre>
  </li>
  </ol>
  <p>So, my questions:</p>
  <ol>
  <li>Is there a way to make it all quicker with less of code?</li>
  <li>How can I create column “Total”, which will contain the sum of values of each row?</li>
  <li>How can I create the row with “Total” in the bottom, which will contain the sum of values of each column?</li>
  </ol>