このようなpythonのコードを実行しようとしています
from gensim import corpora, models, similarities, csv #ファイル読み込み kakunou = open('example.txt') documents = [] for i in kakunou: documents.append(i) # remove common words and tokenize stoplist = set('for a of the and to in'.split()) texts = [[word for word in document.lower().split() if word not in stoplist] for document in documents] # remove words that appear only once all_tokens = sum(texts, []) tokens_once = set(word for word in set(all_tokens) if all_tokens.count(word) == 1) texts = [[word for word in text if word not in tokens_once] for text in texts] with open('example1.csv', 'w') as f: writer = csv.writer(f) # writerオブジェクトを作成 writer.writerows(texts) # 内容を書き込む kakunou.close f.close()
このコードの意図として、example.txtのファイルを読み込んで
リストに格納し、処理を行って
最後にcsvファイルに書き込みたいというコードです
しかし、以下のようなエラーがでます
Traceback (most recent call last): File "corpus.py", line 1, in <module> from gensim import corpora, models, similarities, csv ImportError: cannot import name 'csv'
どう対処すればよいでしょうか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。