我是新手,所以您能帮我吗? 我有一个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的数据框
发布评论