0

So what I am trying to achieve is basically fill in blank rows in a column based off of another columns. so here is a snippet of what my dataframe looks like.

Person_Name     State_Abbrev       Bool
george, John    CT                   NO
george, John    PA                   NO
george, John.   NY                   NO
adam, Ross      NY                   YES
adam, Ross      CA                   NO

So what I want to do is look at the Person_Name column and say if the bool column says no for each of that specific Person_Name and their are no Yes for that person then make a new column and fill in the column with the word question, but if the Person_Name does have at least one row for that specific person_name that has a yes then dont fill in anything for that person and move on to the next person in my dataframe.

Cannon
  • 309
  • 4
  • 19
  • Hi, please let me know if there's any further clarification you need from my answer. Thanks. – cs95 Oct 26 '17 at 15:50
  • My bad I actually meant to accept that answer, thank you that was literally exactly what I needed. – Cannon Oct 27 '17 at 14:40

1 Answers1

1

You're looking for groupby + transform + isin:

df['New'] = df.groupby('Person_Name').Bool\
        .transform(lambda x: 'Question' if ~x.isin(['YES']).any() else '')

df

     Person_Name State_Abbrev Bool       New
0   george, John           CT   NO  Question
1   george, John           PA   NO  Question
2  george, John.           NY   NO  Question
3     adam, Ross           NY  YES          
4     adam, Ross           CA   NO     
cs95
  • 379,657
  • 97
  • 704
  • 746