0

I have this example of pandas dataframe:

C1 C2
ciao type1
anna type1
anna type2

I would run a query on this dataframe to get all rows that are different on the column C2, but are equal on the column C1. In this specific example, I would like to get this table:

C1 C2
anna type1
anna type2

Is it possible? THANKS!

1 Answer 1

1

You can try with groupby and nunique

out = df.groupby('C1').filter(lambda x : any((len(x)>1) & (len(x) == x.nunique())))
Out[167]: 
     C1     C2
1  anna  type1
2  anna  type2
Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much for your answer...But I have a big problem..I don't know why with this csv (ufile.io/xb83mgop) your code doesn't work. Can you help to understand why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.