Интуитивно понятный value_counts
... с помощью метода, предназначенного для этой цели
df.groupby('Author').Comment.value_counts().sort_values(
ascending=False).reset_index(name='Number')
Author Comment Number
0 bob Follow me 4
1 casy Nice picture! 3
2 casy Wow! 2
3 tom I disagree 1
4 linda Interesting post 1
5 linda I like this 1
6 linda Check my profile 1
7 bob Dissapointing 1
pd.factorize
и np.bincount
f, u = pd.factorize(list(zip(df.Author, df.Comment)))
a, c = zip(*u)
pd.DataFrame(dict(
Author=a, Comment=c, Number=np.bincount(f)
)).sort_values('Number', ascending=False)
Counter
from collections import Counter
pd.Series(
Counter(zip(df.Author, df.Comment))
).rename_axis(['Author', 'Comment']).reset_index(name='Number')