0

enter image description here

I want to check which Vin has abs value in column Module. If it has then in the Result column I want Yes wherever that number is present in the column Vin.

  • `df.loc[df['Module'] == 'abs', 'Vin']` –  Mar 18 '22 at 15:13
  • The expected output should be Yes or NO in the Result column(Column C). I want result like I have mentioned in column C – Jawed Sheikh Mar 18 '22 at 16:17
  • Then `df['C'] = (df['Module'] == 'abs').map({True: 'Yes', False: 'No'})` –  Mar 18 '22 at 16:18
  • Hi, @richardec thanks for the reply. You are partially correct. As I mentioned I want Yes if 'abs' is available in particular VIN number. but if that vin no. is repeated in a column then it should right Yes because 'abs' is available for that vin no. – Jawed Sheikh Mar 20 '22 at 07:27
  • I'm sorry, I didn't notice that. I reopened and answered your question :) –  Mar 20 '22 at 14:18

1 Answers1

1

You can first check all the rows where Module == "abs", and then group the result by Vin, and use transform('any') to convert each group to rows of True if the group contains a single True, rows of False otherwise:

df['Result'] = df['Module'].eq('abs').groupby(df['Vin']).transform('any').map({True: 'Yes', False: 'No'})