Skip to content
Advertisement

Pandas Dataframe create new column with grouppy count with condition on count

I have this Dataframe

JavaScript

And I want something like this

JavaScript

I tried this operation

JavaScript

But I have this result

JavaScript

Do you know i could set my condition df.A != df.B on the transform instead on the original dataframe ? Thanks

Advertisement

Answer

For count matched values (Trues) is possible pass mask with sum, Trues are processing like 1 and Falses like 0:

JavaScript

Or create helper column:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement