title: How can I search for and extract a particular value from a dataframe in python?
body: <p>I have a dataframe called "oat" - here is a piece of it:</p>
  
  <pre><code>      Name         Age  Year    T   Neigh One   Neigh Two
  0   Carl P          31  1998    0.1    5454     657
  1   Tyler A         26  2012    3.9    578      98
  2   Antoine G       20  1997    1.7    17       9878
  3   Travis A        23  2008    3.2    199      398
  4   Geoff H         22  1980    -0.3   901      7650
  5   David C         28  2014    4.5    8001     72
  6   Antoine G           21  1998    2.3    5678     9800
  7   Tyler A             25  2011    3.1    2245     450
  </code></pre>
  
  <p>I'm trying to run a for loop through each row.  The values in column "Neigh One" refer to the index of another row, from which, based on particular variables, will lead to another row from which I'd like to extract a variable.   </p>
  
  <p>Here's what I've tried: </p>
  
  <pre><code>for index, row in oat.iterrows():
      indice = row['Neigh One']
      name = oat.iloc[indice]["Name"]
      age = oat.iloc[indice]["Age"]
      age_plus_one = age + 1
      new = oat.loc[(oat.Name == name) &amp; (oat.Age == age_plus_one),'T'].tolist()[0]
  
      print(new)
  </code></pre>
  
  <p>I am getting an error message from the last variable I try, "new."  Basically I am looping through each row, and based on the "Neigh One" value, it will go to that index, and extract the name and age and then add 1. From there, I am looking to find the new row with that same name, but with one added to the age. </p>
  
  <p>Note:  There is either zero rows that will match this, or only one row.  It would be impossible to have more than one match.  </p>
  
  <p>All I want to do is, for each loop, simply return the value of 'T' that comes back based on my boolean filter.  </p>
  
  <p>I have also tried the following for the final variable, with the error messages that each returns: </p>
  
  <pre><code>new= oat[(oat['Name'] == name) &amp; (oat['Age'] == age_plus_one)].T.item()
  </code></pre>
  
  <p>ValueError: can only convert an array of size 1 to a Python scalar</p>
  
  <pre><code>new = oat[(oat['Name'] == name) &amp; (oat['Age'] == age_plus_one),'T'].values[0]
  </code></pre>
  
  <p>not an error, but returns a True of False boolean list for the entire dataframe rather than the actual values. </p>
  
  <pre><code>new = oat.loc[(oat.Name == name) &amp; (oat['Age'] == age_plus_one),'T'].values[0]
  </code></pre>
  
  <p>IndexError: index 0 is out of bounds for axis 0 with size 0</p>
  
  <pre><code>new = oat.loc[(oat.name == name) &amp; (oat.Age == age_plus_one),'T'].tolist()[0]
  </code></pre>
  
  <p>IndexError: list index out of range</p>