Reputation: 23
import numpy as np
import pandas as pd
result = []
unique_id length frame
0 30 12 800
1 30 12 800
2 30 12 700
3 40 600 1200
4 40 800 1200
5 40 600 800
i need to check for each unique_id means for 30 index(0,1,2) length column should be consistent means all (0,1,2) is 12 and frame column all(0,1,2) should be 800. if not display index in to a list.
output: length =[4]
frame=[2,5]
can anyone show me way how i can achieve this.Thanks
Upvotes: 0
Views: 44
Reputation: 150785
Let's try groupby().transform()
:
modes = df.groupby('unique_id').frame.transform(lambda x: x.mode()[0])
out = (df['frame']==modes).sum()
# out: 4
frame = list(df[df['frame']!= modes].index)
# frame: [2,5]
Upvotes: 2