Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. x c
  2. 0 0 1
  3. 1 3 2
  4. 2 1 1
  5. 3 2 1
  6. 4 3 1
  7. 5 4 1
  8. 6 1 0
  9. 7 3 1
  10. 8 2 1
  11. 9 1 2
  12.  
  13. c x duplicated
  14. 0 1 0 False
  15. 1 2 3 False
  16. 2 1 1 False
  17. 3 1 2 True
  18. 4 1 3 True
  19. 5 1 4 False
  20. 6 0 1 False
  21. 7 1 3 True
  22. 8 1 2 True
  23. 9 2 1 False
  24.  
  25. c = np.random.randint(0, 3, 10)
  26. x = np.random.randint(0, 5, 10)
  27. d = pd.DataFrame({'x': x, 'c': c})
  28. d['duplicated'] = d.groupby('c').apply(
  29. lambda x: x.duplicated(keep=False)
  30. ).reset_index(level=0, drop=True)
  31.  
  32. d['duplicated'] = d.duplicated(keep=False)
  33. print (d)
  34. x c duplicated
  35. 0 0 1 False
  36. 1 3 2 False
  37. 2 1 1 False
  38. 3 2 1 True
  39. 4 3 1 True
  40. 5 4 1 False
  41. 6 1 0 False
  42. 7 3 1 True
  43. 8 2 1 True
  44. 9 1 2 False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement