Q:

Remove different pairs form Pandas DataFrame

I have pandas column that has 2 columns with text values:
import pandas as pd

df = pd.DataFrame({"text": ["how are you", "this is an apple", "how are you", "hello my friend", "how are you", "this is an apple", "are you ok", "are you ok"],
                  "type": ["question", "statement", "question", "statement", "statement", "question", "question", "question"]})

print(df)

               text       type
0       how are you   question
1  this is an apple  statement
2       how are you   question
3   hello my friend  statement
4       how are you  statement
5  this is an apple   question
6        are you ok   question
7        are you ok   question

I want to find pairs (2 or more values from 'text' columns) that have different values of 'type' column.
For example, You can see that value "how are you" has 'question' and 'statement'. So my result should be:
               text       type

3   hello my friend  statement
6        are you ok   question
7        are you ok   question

Because text values for 'are you ok' and 'hello my friend' have unique values for "type".
I have tried to remove_duplicates() but that does not work good.
I was thinking about grouping by "text" column, but I do not know how to check if group has different / non unique values of "type" column.

A:

This is groupby().nunique():
df[df.groupby('text')['type'].transform('nunique')==1]

Output:
              text       type
3  hello my friend  statement
6       are you ok   question
7       are you ok   question

