【发布时间】:2021-10-14 19:21:30
【问题描述】:
我正在尝试使用 Python 3.8 进行压缩,但不知道如何访问内容。我现在读到 zip() 是一个生成器,如果我想存储内容,我必须调用 dict(zip()) 。但是,我在执行此操作时遇到了错误。
例如:
from sklearn.feature_extraction.text import CountVectorizer
# initialise
count_vec = CountVectorizer()
word_list = []
for ques_split in [ques.split() for ques in group_wise_ques_list["dbo:genre"]]:
# convert words to lower case
word_list.extend(list(map(str.lower,ques_split)))
print(len(set(word_list)))
group_wise_ques_list = df.groupby(["Processedrelations"])["question"].apply(list)
# transform will normalise the data (if required) and fit will perform the matrix creation
genr_tdm = count_vec.fit_transform(group_wise_ques_list["dbo:genre"])
# convert the raw matrix into a dataframe
genr_tdm_df = pd.DataFrame(genr_tdm.toarray(), columns=count_vec.get_feature_names())
# for NLP, words itself are the features, hence get_feature_names will simply return the set of words
word_list_s = count_vec.get_feature_names();
# count the frequency of each word
count_list_s = genr_tdm.toarray().sum(axis=0)
# create a dictionary with each word as key and its frequency as the value
freq_s = dict(zip(word_list_s,count_list_s))
# sort the dictionary in reverse order
freq_s = sorted(freq_s.items(), key = lambda x : x[1], reverse=True)
# display
freq_s
我收到了这个错误
TypeError: 'ZipFile' object is not callable
【问题讨论】:
-
请包含您的代码的更多详细信息。是否有一个名为
zip的属性,您已为其分配了一个ZipFile对象?? -
我从 zipfile 中添加了 import ZipFile 但它不起作用
-
哪一行出错了?
-
@xsrg45 您是否在代码中使用 zip 文件?请在您的问题中包含您的那部分代码。
-
其打印的