查找单词和绘图结果的频率

问题描述 投票:1回答:1

我目前在文本文件中有一个单词列表,文档中的所有单词都位于单独的行上。我还已将嵌套的json数据导入到pandas数据框中。

Json数据格式看起来与此类似:

[  
   {  
      "year":"2019",
      "category":"chemistry",
      "laureates":[  
         {  
            "id":"976",
            "motivation":"\"for the development of lithium-ion batteries\"",
            "share":"3"
         },
         {  
            "id":"977",
            "motivation":"\"for the development of lithium-ion batteries\"",
            "share":"3"
         }
      ]
   },
   {  
      "year":"2019",
      "category":"economics",
      "laureates":[  
         {  
            "id":"982",
            "firstname":"Abhijit",
            "surname":"Banerjee",
            "motivation":"\"for their experimental approach to alleviating global poverty\"",
            "share":"3"
         },

我需要使用文本文件中的单词来查找json文件中每个类别的各种频率(例如:化学)。然后,我被要求使用Matplotlib为每个主题绘制多个频率(第一个最常见的单词,第10个,第20个,第30个,第40个,第50个)。

我很困惑,因为我不确定执行此操作的最佳方法。

python json matplotlib text-files frequency
1个回答
0
投票

您可以使用python的moses-sacremoses端口进行标记化和规范化。这将为您提供单词列表。然后,您只需要计算每个单词的出现次数并创建图即可。对于快速绘图,我建议使用seabornWord cloud也会很整洁。

© www.soinside.com 2019 - 2024. All rights reserved.