2016-10-21 9 views
1

많은 기능 언어는 map처럼 작동하지만 값을 반환 할 수 있습니다. Spark/pyspark에 해당합니다. http://spark.apache.org/docs/latest/api/python/pyspark.html#pyspark.RDD.flatMapdask의 flatMap

dask에서 가장 좋은 방법은 무엇입니까? 내 코드는 다음과 같습니다 dicts의

import dask.bag as db 
import json 
from tools import get_records 

records = db.read_text(json_file).map(json.loads).map(get_records) 

get_records 반환 목록입니다. 하나의 시퀀스로 묶어야합니다.

답변

2

당신은 아마이 작업은 "지도"를 원하는대로 개별적으로 사용하거나 체인 수 있습니다 "CONCAT"가있는 .concat method

In [1]: import dask.bag as db 

In [2]: b = db.from_sequence([1, 2, 3, 4, 5]) 

In [3]: def f(i): 
    ...:  return list(range(i)) 
    ...: 

In [4]: b.map(f).compute() 
Out[4]: [[0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] 

In [5]: b.map(f).concat().compute() 
Out[5]: [0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4] 

그래서 대신에 합류 "flatMap"작업을 할 수 있습니다.

관련 문제