以前、この質問に関する質問をさせていただきましたが、質問の仕方を変えた方がよいと感じ、新しく質問させてください。
私は、あるjsonファイルを使用しています。
私のjsonファイルは、下のURLのjsonファイルでワインについてのレビューについてのデータで、多くの種類のワインのレビューについてリストとして記載されています。
'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/wine.json'
行には”country”,"variety", "price", "point", "description"などの項目があります。
私のjsonファイルは下のような表になります。(1行が1レビューになってます。)
私は、このファイルの"description"の列で5000件以上のレビューに現れるユニグラムを求めることを目的としています。
また、ストップワードとして'stopwords.txt'に記載された単語を”description”から省いた状態でもとめなければなりません。
下のURLが'stopwords.txt'となっています。
'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/stopwords.txt'
以下が"description"の列で5000件以上のレビューに現れるユニグラムを求めるためのコードのテンプレートとなっています。
python
1import re 2import nltk 3from nltk.tokenize import RegexpTokenizer 4from nltk.probability import * 5from itertools import chain 6#from tqdm import tqdm 7import codecs
python
1with open('stopwords.txt') as f: 2 stop_words = f.read().splitlines() 3stop_words = set(stop_words)
python
1# write your code here 2# define your tokenize 3 4tokenizer = RegexpTokenizer(r"\w+(?:[-']\w+)?")
python
1# find top common words with document frequencies > 5000 2# you may use function FreqDist() and sort()
python
1# save your table to 'top_common_words.txt'
そして、下のコードが私が書いたコードです。
python
1!pip install wget
python
1import wget 2 3link_to_data = 'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/wine.json' 4DataSet = wget.download(link_to_data) 5 6link_to_data = 'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/stopwords.txt' 7 8DataSet = wget.download(link_to_data)
python
1!ls
python
1import json 2import pandas as pd 3import matplotlib.pyplot as plt
python
1file = 'wine.json'
python
1df = pd.read_json("wine.json")
python
1import re 2import nltk 3from nltk.tokenize import RegexpTokenizer 4from nltk.probability import * 5from itertools import chain 6 7import codecs
python
1with open('stopwords.txt') as f: 2 stop_words = f.read().splitlines() 3stop_words = set(stop_words)
python
1tokenizer = RegexpTokenizer(r"\w+(?:[-']\w+)?")
ファイルの"description"の列で5000件以上のレビューに現れるユニグラムを求めたい場合、私は自分が書いたコードの次にテンプレート通りに FreqDist()とsort()を使用すれば、そのまま"description"の列で5000件以上のレビューに現れるユニグラムを求めることができるのでしょうか。
それとも、 FreqDist()とsort()を使用する前にストップワードの記載された'stopwords.txt'を新たに”description”適応したりするためにほかにコードを書く必要があるのでしょうか。もしくは、そのほかにも何か書くべきコードがありましたら教えて頂けますでしょうか。
つまり、下に書いたテンプレートの部分でそれ以前に余分に書くべきコードが私の書いたコードと比較して何かある場合は教えて頂けますでしょうか。
python
1# find top common words with document frequencies > 5000 2# you may use function FreqDist() and sort()
お願いいたします。
回答1件
あなたの回答
tips
プレビュー