'I want to check which Vin has abs value in column Module

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.



Solution 1:[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'})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 richardec