1は、私は、教育的な理由のために、唯一python
の標準ライブラリで、この簡易版を書きました。他の人が質問が本当にあいまいですが、あなたが新しく追加されたので、ここで長い形式のガイドです言ったように
量産コードはspacy
とpandas
import collections
from operator import itemgetter as at
with open("input.csv",'r') as f:
data = [l.split(',', 2) for l in f.readlines()]
spaced = lambda t: (t[0][0],' '.join(map(at(1), t))) if t[0][0]==t[1][0] else []
unigrams = [(i,w) for i, d in data for w in d.split()]
bigrams = filter(any, map(spaced, zip(unigrams, unigrams[1:])))
trigrams = filter(any, map(spaced, zip(unigrams, unigrams[1:], unigrams[2:])))
with open("output.csv", 'w') as f:
for ngram in [unigrams, bigrams, trigrams]:
counts = collections.Counter(ngram)
for t,count in counts.items():
f.write("{i},{w},{c}\n".format(c=count, i=t[0], w=t[1]))
こんにちは、あなたに試したことのいくつかのコードを含めることはできますか?主な問題は何ですか? –
私たちはコーディングサービスではありません。あなたが何をしたのか、どこにいるのか教えてください。 –
ファイルを書くために 'open'や' csv.writer'が必要な場合は、 'collections'から' Counter'をお勧めします。あなたは、unique_ID文字列内の頻度を、まったく同じにしますか? –