title: Creating new variable using information from multiple lines in dataframe
body: <p>I have a dataframe which looks like this:</p>
  
  <pre><code>df = pd.DataFrame({"HouseholdNumber": [1, 1, 1, 1, 1, 2, 2], "TypeOfPerson": ["Son", "Daughter", "Daughter", "Parent", "Parent", "Daughter", "Parent"], "Age": [17, 10, 20, 52, 45, 22, 50]})
  print(df)
     HouseholdNumber TypeOfPerson  Age
  0                1          Son   17   
  1                1     Daughter   10   
  2                1     Daughter   20  
  3                1       Parent   52     
  4                1       Parent   45    
  5                2     Daughter   22    
  6                2       Parent   50      
  </code></pre>
  
  <p>and I want to create a new variable using information from multiple lines. This is a problem for me because I'm having problems with using a simple <code>df.loc</code> (or <code>np.where</code>) condition. Specifically, I want the new variable to have the value <code>no</code> in case the person is not a parent or has no child in the age groups, an <code>a</code> if the parent has a child which is 18 years old or younger and a <code>b</code> if the parent has a child which is between 19 and 25 years old. If the parents have a child of both age groups, the value should still be an <code>a</code>. The HouseholdNumber indicates the different families, so all the conditions should apply for each Household. So, the dataframe should look like this:</p>
  
  <pre><code>   HouseholdNumber TypeOfPerson  Age Child
  0                1          Son   17    no
  1                1     Daughter   10    no
  2                1     Daughter   20    no
  3                1       Parent   52     a
  4                1       Parent   45     a
  5                2     Daughter   22    no
  6                2       Parent   50     b 
  </code></pre>
  
  <p>The code I'm trying is</p>
  
  <pre><code>df["Child"]=""
  for i in df["HouseholdNumber"].unique():
      if (df.loc[df.TypeOfPerson.isin(["Son", "Daughter"]) &amp; (df.Age &lt;= 18)]):
         if (df.loc[(df.TypeOfPerson == "Parent")]):
             df["Child"] = "a"
      elif (df.loc[df.TypeOfPerson.isin(["Son", "Daughter"]) &amp; ((df.Age &gt;= 19) &amp; (df.Age &lt;= 26))]):
         df["Child"] = "b"
      else:
          df["Child"] = "no"
  </code></pre>
  
  <p>which gives me the error <code>The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()</code>. I'm not really sure where to go from here, I always get this error. Even without the error I suspect that my code will not give the desired result though.</p>