【问题标题】:dask concat not supported in latest version最新版本不支持 dask concat
【发布时间】:2020-01-14 12:33:24
【问题描述】:

我正在尝试测试此页面上的 dask 命令...

https://extrapolations.dev/blog/2015/07/reproduceit-reddit-word-count-dask/

我在这一行遇到错误:

words = body.map(nltk.word_tokenize).concat()

我猜 dask API 自从文章发表以来已经发生了变化。如何使用此文件重写它...

aws s3 cp s3://reddit-cmets/2007/RC_2007-10 .

到目前为止,我已经成功运行了这段代码:

import re
import json
import time
import nltk
import dask
import dask.bag as db
import nltk
from nltk.corpus import stopwords

data = db.read_text("RC_2007-10" ).map(json.loads)
no_stopwords = lambda x: x not in stopwords.words('english')

is_word = lambda x: re.search("^[0-9a-zA-Z]+$", x) is not None

subreddit = data.filter(lambda x: x['subreddit'] == 'movies')
bodies = subreddit.pluck('body')

【问题讨论】:

    标签: dask


    【解决方案1】:

    我认为您正在寻找 flatten 方法:

    In [1]: import dask.bag as db                                                   
    
    In [2]: b = db.from_sequence([[1, 2, 3], [4, 5, 6]])                            
    
    In [3]: b.flatten().compute()                                                   
    Out[3]: [1, 2, 3, 4, 5, 6]
    

    https://docs.dask.org/en/latest/bag-api.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 2020-03-08
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多