I have a dataframe df with 50,000+ rows:
>>> df
message words wordCount uniqueWordCount
0 my name is [my, name, is] 3 3
1 happy birthday to you [happy, birthday, to, you] 4 4
2 la la la la la [la, la, la, la, la] 5 1
3 you are you that is it [you, are, you, that, is, it] 6 5
...
I want to create a new column with the 3 most frequent words in the message.
What I have so far works, but takes quite some time.
>>> df["mostFrequent"] = df["message"].apply(
lambda x: sorted(
textblob.TextBlob(x).word_counts, key=textblob.TextBlob(x).word_counts.get, reverse=True)[:3])
>>> df["mostFrequent"]
0 [my, name, is]
1 [happy, birthday, to]
2 [la]
3 [you, are, that]
...
Is there a more efficient way of doing this?