-1

enter image description here

Hello. I stuck here. Could you tell me how can I count words based on the tags on the second column?

I want to find mostly used words using .most_common() using the categorize: most 10 in VB(Verb), 10 in Noun.

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
  • 3
    Welcome to Stackoverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Jun 11 '20 at 06:24
  • [Please don't post images of code/data (or links to them)](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question) – jezrael Jun 11 '20 at 06:25
  • You can split the dataframe based on the values in that column, then do your `.most_common()` counts on the new datasets. See: [Pandas split DataFrame by column value](https://stackoverflow.com/questions/33742588/pandas-split-dataframe-by-column-value) – Ari Cooper-Davis Jun 11 '20 at 06:57
  • Have you ever tried `collections.Counter()` ? https://docs.python.org/3/library/collections.html#collections.Counter – alec_djinn Jun 11 '20 at 11:41

1 Answers1

1

To spell out what Ari Cooper-Davis suggested:

pos.loc[pos.tag == 'VBN'].word.value_counts()
pos.loc[pos.tag == 'TO'].word.value_counts()

etc.
dwolfeu
  • 1,103
  • 2
  • 14
  • 21