我想并行化一个函数,该函数在dict中返回一个平坦的值列表(称为“keys”),但我不知道如何获得最终结果。我试过:
def toParallel(ht, token):
keys = []
words = token[token['hashtag'] == ht]['word']
for w in words:
keys.append(checkString(w))
y = {ht:keys}
num_cores = multiprocessing.cpu_count()
pool = multiprocessing.Pool(num_cores)
token = pd.read_csv('/path', sep=",", header = None, encoding='utf-8')
token.columns = ['word', 'hashtag', 'count']
hashtag = pd.DataFrame(token.groupby(by='hashtag', as_index=False).count()['hashtag'])
result = pd.DataFrame(index = hashtag['hashtag'], columns = range(0, 21))
result = result.fillna(0)
final_result = []
final_result = [pool.apply_async(toParallel, args=(ht,token,)) for ht in hashtag['hashtag']]
Where toParallel函数应该返回一个以hashtag作为key的dict和一个键列表(其中keys是int)。但如果我试图打印最终结果,我只得到
bound method ApplyResult.get of multiprocessing.pool.ApplyResult object at 0x10c4fa950
我该怎么做?在
差别是operator precedence
+
优先于&
,但&
优先于+=
。因此,您的操作转化为:在第一种情况下,n将首先加上0,然后再加上1
运营者及;优先级低于+
你实际上写的是:
我加了括号来澄清
因为n是偶数,所以该表达式的结果为零
相关问题 更多 >
编程相关推荐