YellowPillow
YellowPillow

Reputation: 4270

How would I make this filter query using pandas

Given that I have a data frame:

  UID   | booleanCondition
------------------------------
 uid1   |   True
 uid1   |   False
 uid2   |   True
 uid2   |   True

How can I find the UIDs that have had their booleanCondition changed? I know that I can do this by looping through the data frame using the .as_matrix() command but is there a way where I don't need to do that?

Upvotes: 0

Views: 24

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

You can try this:

 df.groupby('UID').filter(lambda x: (x.booleanCondition != x.booleanCondition.shift()).all())

Output:

        UID  booleanCondition
1   uid1                 True
2   uid1                False

Upvotes: 1

Related Questions