更新dask的数据框

编程入门 行业动态 更新时间:2024-10-09 20:21:27
本文介绍了更新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_dfpute().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的数据框

本文发布于:2023-11-22 08:00:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   dask

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!