Pandas - Use Groupby And Filter On Multiple Conditions
I am trying to group a dataset by IDs, then by time. Then, I want to select records based on the criteria of one column and based on time by ID. I have been researching and playing
Solution 1:
We need groupby
+ shift
,
df.loc[(df.groupby(["a"]).value2.shift()+df.value2).eq('OrangeApple'),'a']
Out[287]:
2 A1
6 A3
9 A2
Name: a, dtype: object
df.loc[(df.groupby(["a"]).value2.shift()+df.value2).eq('OrangeApple'),'a'].nunique()
Out[288]: 3
Post a Comment for "Pandas - Use Groupby And Filter On Multiple Conditions"