2017-05-31 59 views
0

該過濾器查詢假設我有一個數據幀:我怎麼會讓使用熊貓

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

我怎樣才能找到UIDs有他們booleanCondition改變?我知道我可以通過使用.as_matrix()命令循環訪問數據框來完成此操作,但有沒有辦法可以避免這種情況?

+0

你所說的 「改變」 是什麼意思?從何而來?在這種情況下,你只是想按'booleanCondition == True'來過濾嗎?你想要的輸出是什麼? – pshep123

回答

1

你可以試試這個:

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

輸出:

 UID booleanCondition 
1 uid1     True 
2 uid1    False