更新dask的数据框 [英] Update of dask's dataframe

查看:78
本文介绍了更新dask的数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,所以您能帮我吗?
我有一个csv文件,例如:

I'm new to dask so could you help me please? I have a csv-file like this:

id,popularity,hashtag,seen
0,100,#footbal,0
1,200,#2017,0
2,300,#1,0

以某种方式我设法获得了一个淡淡的数据框 hashtags_to_update

and somehow i managed to get a dask dataframe hashtags_to_update:

id  seen
0   118
2   136

我想合并来自 hashtags_to_update 的数据和来自csv文件的数据来获取:

I'd like to merge a data from hashtags_to_update with data from csv-file to get:

id,popularity,hashtag,seen
0,100,#footbal,118
1,200,#2017,0
2,300,#1,136

现在我正在执行以下操作

For now I'm doing the following

hashtags_df = dd.read_csv('path/to/csv/file').set_index('id')
hashtags_df["seen"] = hashtags_df["seen"].add(hashtags_to_update["seen"], fill_value=0).astype('int64')
hashtags_df.compute().to_csv('output.csv', sep=',')

但是据我所知,当数据包含字符串时被强制转换为python的对象,因此不会因为GIL而产生并行性。

But as far as I know there are some problems when the data contains strings which are casted as python's objects, so there will be no parallelism because of GIL.

您有什么可以建议我做的吗?

Is there anything you could advice me to do? Thank you in advance.

推荐答案

您可以使用多重处理(从而避免了GIL)。

you can use multiprocessing (thus avoiding the GIL).

有几种方法:

设置客户端(默认情况下,它将确保多处理):

setup a client (by default it will ensure multiprocessing):

from dask.distributed import Client
client = Client()

import dask.multiprocessing
dask.config.set(scheduler='processes')  # overwrite default with multiprocessing scheduler 

覆盖默认值。

更多信息:

客户端

dask.config.set

这篇关于更新dask的数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆