title: Extract max and min values of entries in one column based on the combined values of two other columns in csv
body: <p>I have a csv file that looks something like this:</p>
  <p><a href="https://i.stack.imgur.com/Xz4pC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xz4pC.png" alt="enter image description here" /></a></p>
  <p>I'm trying to extract the max and min values from the &quot;Assigned&quot; column based on the combined values of the &quot;Animal ID&quot; and &quot;Farm ID&quot; columns.</p>
  <p>Ex. if the &quot;Animal ID&quot; = 10 and &quot;Farm ID&quot; = 10, I need to find its max value (0.23 in this case) and its min value (0.12 in this case) and subtract the two. Then, I want to do the same for when &quot;Animal ID&quot; = 10 and &quot;Farm ID&quot; = 20 and so on. I tried the following, however, I get the following error: <code>KeyError: 'Assigned'</code>. I'm not sure where I'm going wrong. Also, if there's a better way to achieve this than the method I'm using, I'd really appreciate learning about that.</p>
  <p>This is what I have done so far:</p>
  <pre><code>if df['AnimalID'].all() ==0 and df['Farm ID'].all() ==0:
      print(df.loc['Assigned'].max() - df.loc['Assigned'].min())
  </code></pre>
  <p>Expected Output for <code>Animal ID = 10</code> and <code>Farm ID = 10</code>: 0.11
  Expected Output for <code>Animal ID = 10</code> and <code>Farm ID = 20</code>: 0.06</p>