get/access dask.dataframe(df, chunksize=100) 的每个块
get/access each chunk of dask.dataframe(df, chunksize=100)
我使用以下代码使用 dask 拆分数据帧:
result=dd.from_pandas(df, chunksize=75)
我使用以下代码创建自定义 json 文件:
for z in result:
createjson (z)
就是没用!我怎样才能访问每个块?
可能有更原生的方式(感觉应该有)但你可以这样做:
for i in range(result.npartitions):
partition = result.get_partition(i)
# your code here
我们不知道您的 createjson
功能是做什么的,但也许 to_json()
涵盖了它。
或者,如果您真的想对每个分区做一些独特的事情,而这不是 JSON 所独有的,那么您将需要方法 map_partitions()
.
我使用以下代码使用 dask 拆分数据帧:
result=dd.from_pandas(df, chunksize=75)
我使用以下代码创建自定义 json 文件:
for z in result:
createjson (z)
就是没用!我怎样才能访问每个块?
可能有更原生的方式(感觉应该有)但你可以这样做:
for i in range(result.npartitions):
partition = result.get_partition(i)
# your code here
我们不知道您的 createjson
功能是做什么的,但也许 to_json()
涵盖了它。
或者,如果您真的想对每个分区做一些独特的事情,而这不是 JSON 所独有的,那么您将需要方法 map_partitions()
.