我目前在一个文本文件中有一个单词列表,文档中的所有单词都在单独的一行上。我还将嵌套的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)。
我很困惑,因为我不确定最好的方法。
发布于 2019-12-03 22:40:56
您可以使用python的moses - sacremoses端口进行标记化和规范化。这将为您提供单词列表。然后,您只需要计算每个单词的出现次数并创建曲线图。对于快速绘图,我推荐使用seaborn。Word cloud也会很整洁。
https://stackoverflow.com/questions/59159240
复制相似问题