我将两篇论文的处理数据合二为一。我想创建一组两个计算使用了多少不同的单词以及其他分析。但是,当我将它们组合并执行 set(entire) 时,返回的只是一组字母。我有下面的代码以及我得到的输出。我希望输出是所有正在使用的单词。
print set(entire)
set([' ', '1', '0', '3', '2', '5', '4', '6', '9', 'a', 'c', 'b', 'e', 'd', 'g', 'f', 'i', 'h', 'k', 'j', 'm', 'l', 'o', 'n', 'p', 's', 'r', 'u', 't', 'w', 'v', 'y', 'x'])
from __future__ import division
import nltk
import csv
import re
from string import punctuation
import enchant
from enchant.checker import SpellChecker
dictionary = enchant.Dict("en_US")
chkr = SpellChecker("en_US")
with open('2012ShortAnswers.csv', 'rb') as csvfile:
data = csv.reader(csvfile, delimiter=",")
writer = csv.writer(open('2012output.csv', 'wb'))
for row in data:
row3 = row[3]
row3 = row3.lower().replace(' ', ' ')
row4 = row[4]
row4 = row4.lower().replace(' ', ' ')
row3 = row3.replace('\n', '')
row4 = row4.replace('\n', '')
for p in list(punctuation):
row3 = row3.replace(p, '')
row4 = row4.replace(p, '')
entire = row3 + row4
set(entire)