CopyPastor

Detecting plagiarism made easy.

Score: 0.8113592267036438; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-09-01
by user3483203

Original Post

Original - Posted on 2018-07-29
by Wen



            
Present in both answers; Present only in the new answer; Present only in the old answer;

### Using `numpy.where`:
df.assign( target=np.where(df.index.isin(df.groupby(['Group1', 'Group2']).Value.idxmax()), df.Value, 0) )
<!- ->
Group1 Group2 Value target 0 1 3 0 0 1 1 3 1 1 2 1 4 1 1 3 1 4 1 0 4 2 5 5 5 5 2 5 1 0 6 2 6 0 0 7 2 6 1 1

Using `idxmax`
df['Newcol']=0 df.loc[df.Value.ne(0).groupby(df['Group']).idxmax(),'Newcol']=1 df Out[41]: Group Value Target_Column Newcol 0 1 0 0 0 1 1 0 0 0 2 1 1 1 1 3 1 2 0 0 4 2 0 0 0 5 2 1 1 1 6 2 0 0 0 7 2 1 0 0


        
Present in both answers; Present only in the new answer; Present only in the old answer;