简体   繁体   English

将繁重的计算功能应用于dask数据帧的最有效方法?

[英]Most efficient way of applying a compute-heavy function to a dask dataframe?

I have a ~6000 rows long dataframe. 我有一个〜6000行长的数据框。 I need to apply a function (let's call it heavy_func ) to all rows of a specific column, which takes up to a minute per call. 我需要对特定列的所有行应用一个函数(我们称其为heavy_func ),每次调用最多需要一分钟。 The input to the function is a string, and the output an np.array. 该函数的输入是一个字符串,而输出是一个np.array。

I am using dask distributed to set up a cluster on which to perform the apply's. 我正在使用dask distributed来设置执行应用程序的集群。 Right now I use 80 workers with 4 cores and 8 GB RAM per worker. 现在,我使用80个工作人员,每个工作人员有4个内核和8 GB RAM。

The actual apply step looks like this: 实际的应用步骤如下所示:

ddf = dd.from_pandas(df, npartitions=100)

ddf['new_col'] = ddf.apply(heavy_func, axis=1, meta=('ddf', 'object'))
df = ddf.compute()

I'm wondering how to maximize efficiency here. 我想知道如何在这里最大化效率。

Should I maximize workers or cores? 我应该最大化工作人员或核心人员吗? In what ratio should the nr. nr应该以什么比例。 of partitions and nr. 分区和nr。 of workers/cores be? 工人/核心是?

I'm also unsure whether using map_partitions instead of apply would have any benefits. 我也不确定使用map_partitions而不是apply是否会有任何好处。

For processes and threads you may want to read this: https://docs.dask.org/en/latest/best-practices.html#processes-and-threads 对于进程和线程,您可能需要阅读以下内容: https : //docs.dask.org/en/latest/best-practices.html#processes-and-threads

It depends on how much your computation releases the GIL. 这取决于您的计算释放GIL的程度。

Using apply vs map_partitions shouldn't make much difference here. 在这里使用apply vs map_partitions应该不会有太大的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 pandas 中计算平方 dataframe 的最有效方法 - Most efficient way to compute a square dataframe in pandas 计算dask数据帧中所有行差异的有效方法 - Efficient way to compute difference of all rows in dask dataframe 根据条件应用 function 的最有效方法 - Most efficient way of applying a function based on condition 将 function 应用于 dask dataframe 中的列的最有效方法是什么? - What is the most efficient method to apply a function to a column in a dask dataframe? Dask:将自定义函数应用于 DataFrame 出现错误 - Dask: applying custom function to DataFrame gets error 将函数应用于 Pandas 数据帧:是否有更节省内存的方法? - Applying function to pandas dataframe: is there a more memory-efficient way of doing this? Dask 将 function 应用于 dataframe 返回相同的结果 - Dask returns the same result applying a function to a dataframe 在应用函数之前强制Dask Delayed对象计算所有参数 - Force a Dask Delayed object to compute all parameters before applying the function Dask dataframe 计算失败 - Dask dataframe compute failed 将 Python 函数应用于 Pandas 分组数据帧 - 加速计算的最有效方法是什么? - Applying Python function to Pandas grouped DataFrame - what's the most efficient approach to speed up the computations?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM