I have a dataframe
df = pd.DataFrame({'Con_Num': [1, 1, 1, 1, 2, 2, 2, 2, 3, 3],
'Con_Type': ['A', 'A', 'B', 'C', 'A', 'B', 'B', 'C', 'C', 'C'],
'Is_Prim':['No','Yes','No','No','No','No','No','Yes','No','Yes']})
Out[298]:
Con_Num Con_Type Is_Prim
0 1 A No
1 1 A Yes
2 1 B No
3 1 C No
4 2 A No
5 2 B No
6 2 B No
7 2 C Yes
8 3 C No
9 3 C Yes
I want to update the Con_Type column, so the value is the same for every group (based off grouping by Con_Num). The value I want in that column is the row where Is_Prim==Yes.
I've seen the transform function but have been unsuccessful in figuring out how to map based off another column.
My output based off the example dataframe would be as follows:
Con_Num Con_Type Is_Prim
0 1 A No
1 1 A Yes
2 1 A No
3 1 A No
4 2 C No
5 2 C No
6 2 C No
7 2 C Yes
8 3 C No
9 3 C Yes
I don't want to deduplicate, there are other columns I need but are irrelevant to this problem.