简体   繁体   English

为什么我的代码需要这么长时间才能在Dask Python中写入CSV文件

[英]Why does my code take so long to write CSV file in Dask Python

Below is my Python code: 下面是我的Python代码:

import dask.dataframe as dd

VALUE2015 = dd.read_csv('A/SKD - M2M by Salesman (value by uom) (NEWSALES)2015-2016.csv', usecols = VALUEFY, dtype = traintypes1) 

REPORT = VALUE2015.groupby(index).agg({'JAN':'sum', 'FEB':'sum', 'MAR':'sum', 'APR':'sum', 'MAY':'sum','JUN':'sum', 'JUL':'sum', 'AUG':'sum', 'SEP':'sum', 'OCT':'sum', 'NOV':'sum', 'DEC':'sum'}).compute()

REPORT.to_csv('VALUE*.csv', header=True)

It takes 6 minutes to create a 100MB CSV file. 创建100MB CSV文件需要6分钟。

Looking through Dask documentation, it says there that, "generally speaking, Dask.dataframe groupby-aggregations are roughly same performance as Pandas groupby-aggregations." 查看Dask文档时,它说:“一般而言,Dask.dataframe groupby聚合与Pandas groupby聚合大致具有相同的性能。” So unless you're using a Dask distributed client to manage workers, threads, etc., the benefit from using it over vanilla Pandas isn't always there. 因此,除非您使用Dask分布式客户端来管理工作程序,线程等,否则使用它取代普通Pandas的好处并不总是存在的。

Also, try to time each step in your code because if the bulk of the 6 minutes is taken up by writing the .CSV to file on disk, then again Dask will be of no help (for a single file). 另外,请尝试对代码中的每个步骤进行计时,因为如果6分钟的大部分时间是通过将.CSV写入磁盘上的文件来完成的,那么Dask再也无济于事(对于单个文件)。

Here 'sa nice tutorial from Dask on adding distributed schedulers for your tasks. 是来自Dask的不错的教程,关于为您的任务添加分布式调度程序。

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

相关问题 为什么我的多处理代码需要这么长时间才能在 python 3.9 中完成,而不是 python 2.7。 代码改进? - Why does my multiprocessing code take so long to complete in python 3.9, but not python 2.7. Code improvements? 为什么在过滤后的 Dask 数据帧上运行计算()需要这么长时间? - Why does running compute() on a filtered Dask dataframe take so long? 为什么这段代码要花这么长时间才能执行? -Python - Why does this code take so long to be executed? - Python 为什么 Python 需要这么长时间来处理我的正则表达式? - Why does Python take so long to process my Regex? 为什么填充我的桌子需要这么长时间? - Why does populating my table take so long? 为什么我的带有 jit 函数的模块需要这么长时间才能导入? - Why does my module with jit functions take so long to import? 当字典在函数中时,为什么我的 Fibonacci 需要这么长时间? - Why does my Fibonacci take so long when the dictionary is in the function? 为什么`eval` function 在 Python 中似乎需要这么长时间? - Why does the `eval` function seemingly take so long in Python? 为什么无论 dataframe 的大小如何,dask 都需要很长时间来计算 - Why does dask take long time to compute regardless of the size of dataframe 为什么我的代码没有写入写入 CSV 中指示的文件路径? - Why does my code not write to my file path indicated in write to CSV?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM