Чтобы найти наиболее часто встречающиеся слова, вы можете использовать collections.Counter
:
from collections import Counter
df = pd.DataFrame({
'Animal': ['dog', 'dog', 'cat', 'cat', 'cat', 'rabbit'] ,
'Description':['woof hairy', 'hairy big', 'meow', 'meow', 'meow whiskers', 'carrot']
})
most_common = {}
for animal, grp_df in df.groupby('Animal')['Description']:
counts = Counter([word for phrase in grp_df.tolist() for word in phrase.split(' ')])
most_common[animal] = max(counts.keys(), key=lambda x: counts[x])
Вывод:
{'cat': 'meow', 'dog': 'hairy', 'rabbit': 'carrot'}