Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df=pd.DataFrame([["casy","Nice picture!"],
- ["linda","I like this "],
- ["casy ","Nice picture! "],
- ["tom ","I disagree "],
- ["bob ","Follow me "],
- ["bob ","Follow me "],
- ["bob ","Follow me "],
- ["bob ","Follow me "],
- ["casy ","Nice picture! "],
- ["casy ","Wow! "],
- ["linda ","Interesting post "],
- ["linda","Check my profile"],
- ["bob ","Dissapointing"],
- ["casy ","Wow! "]
- ] ,columns=["Author","Comment"])
- df
- Author Comment
- 0 casy Nice picture!
- 1 linda I like this
- 2 casy Nice picture!
- 3 tom I disagree
- 4 bob Follow me
- 5 bob Follow me
- 6 bob Follow me
- 7 bob Follow me
- 8 casy Nice picture!
- 9 casy Wow!
- 10 linda Interesting post
- 11 linda Check my profile
- 12 bob Dissapointing
- 13 casy Wow!
- df_sorted = (df.groupby(['Author', 'Comment'], sort=False).size()
- .sort_values(ascending=False)
- .reset_index(name='Number')
- .reindex(columns=['Author','Number','Comment']))
- df_sorted
- Author Number Comment
- 0 bob 4 Follow me
- 1 casy 2 Wow!
- 2 casy 2 Nice picture!
- 3 bob 1 Dissapointing
- 4 linda 1 Check my profile
- 5 linda 1 Interesting post
- 6 tom 1 I disagree
- 7 linda 1 I like this
- 8 casy 1 Nice picture!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement