1
Df1: Id Name 1 A 2 B 3 B 3 A 2 A 6 B 

I need to create a new column Based on Id and Name Column. If same Id is present Name Column Values. For Example Id 3,2 present for both A and B.

Df1:

Id Name New_Col 1 A Unique 2 B Common 3 B Common 3 A Common 2 A Common 6 B Unique 
1
  • Do you only need to check if the id is unique? Commented Apr 5, 2021 at 19:58

1 Answer 1

1

Try with transform + nunique

df'[out'] = np.where( df.groupby('Id')['Name'].transform('nunique').eq(1), 'Unique', 'Common') Out[519]: 0 Unique 1 common 2 common 3 common 4 common 5 Unique Name: Name, dtype: object 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.