Advertisement
Guest User

Untitled

a guest
May 27th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. df=pd.DataFrame([["casy","Nice picture!"],
  2. ["linda","I like this "],
  3. ["casy ","Nice picture! "],
  4. ["tom ","I disagree "],
  5. ["bob ","Follow me "],
  6. ["bob ","Follow me "],
  7. ["bob ","Follow me "],
  8. ["bob ","Follow me "],
  9. ["casy ","Nice picture! "],
  10. ["casy ","Wow! "],
  11. ["linda ","Interesting post "],
  12. ["linda","Check my profile"],
  13. ["bob ","Dissapointing"],
  14. ["casy ","Wow! "]
  15. ] ,columns=["Author","Comment"])
  16.  
  17.  
  18. df
  19.  
  20. Author Comment
  21. 0 casy Nice picture!
  22. 1 linda I like this
  23. 2 casy Nice picture!
  24. 3 tom I disagree
  25. 4 bob Follow me
  26. 5 bob Follow me
  27. 6 bob Follow me
  28. 7 bob Follow me
  29. 8 casy Nice picture!
  30. 9 casy Wow!
  31. 10 linda Interesting post
  32. 11 linda Check my profile
  33. 12 bob Dissapointing
  34. 13 casy Wow!
  35.  
  36. df_sorted = (df.groupby(['Author', 'Comment'], sort=False).size()
  37. .sort_values(ascending=False)
  38. .reset_index(name='Number')
  39. .reindex(columns=['Author','Number','Comment']))
  40. df_sorted
  41.  
  42.  
  43. Author Number Comment
  44. 0 bob 4 Follow me
  45. 1 casy 2 Wow!
  46. 2 casy 2 Nice picture!
  47. 3 bob 1 Dissapointing
  48. 4 linda 1 Check my profile
  49. 5 linda 1 Interesting post
  50. 6 tom 1 I disagree
  51. 7 linda 1 I like this
  52. 8 casy 1 Nice picture!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement