Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x c
- 0 0 1
- 1 3 2
- 2 1 1
- 3 2 1
- 4 3 1
- 5 4 1
- 6 1 0
- 7 3 1
- 8 2 1
- 9 1 2
- c x duplicated
- 0 1 0 False
- 1 2 3 False
- 2 1 1 False
- 3 1 2 True
- 4 1 3 True
- 5 1 4 False
- 6 0 1 False
- 7 1 3 True
- 8 1 2 True
- 9 2 1 False
- c = np.random.randint(0, 3, 10)
- x = np.random.randint(0, 5, 10)
- d = pd.DataFrame({'x': x, 'c': c})
- d['duplicated'] = d.groupby('c').apply(
- lambda x: x.duplicated(keep=False)
- ).reset_index(level=0, drop=True)
- d['duplicated'] = d.duplicated(keep=False)
- print (d)
- x c duplicated
- 0 0 1 False
- 1 3 2 False
- 2 1 1 False
- 3 2 1 True
- 4 3 1 True
- 5 4 1 False
- 6 1 0 False
- 7 3 1 True
- 8 2 1 True
- 9 1 2 False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement