dask

Writing Dask partitions into single file

给你一囗甜甜゛ 提交于 2019-11-30 13:43:08
问题 New to dask ,I have a 1GB CSV file when I read it in dask dataframe it creates around 50 partitions after my changes in the file when I write, it creates as many files as partitions. Is there a way to write all partitions to single CSV file and is there a way access partitions? Thank you. 回答1: Short answer No, Dask.dataframe.to_csv only writes CSV files to different files, one file per partition. However, there are ways around this. Concatenate Afterwards Perhaps just concatenate the files

Slow len function on dask distributed dataframe

空扰寡人 提交于 2019-11-30 12:30:19
I have been testing how to use dask (cluster with 20 cores) and I am surprised by the speed that I get on calling a len function vs slicing through loc. import dask.dataframe as dd from dask.distributed import Client client = Client('192.168.1.220:8786') log = pd.read_csv('800000test', sep='\t') logd = dd.from_pandas(log,npartitions=20) #This is the code than runs slowly #(2.9 seconds whilst I would expect no more than a few hundred millisencods) print(len(logd)) #Instead this code is actually running almost 20 times faster than pandas logd.loc[:'Host'].count().compute() Any ideas why this

How to see progress of Dask Compute task?

旧时模样 提交于 2019-11-30 11:19:45
I would like to see a progressbar on Jupyternotebook while i'm running a compute task using Dask, I'm counting all values of "id" column from a large csv file +4GB, so any ideas? import dask.dataframe as dd df = dd.read_csv('data/train.csv') df.id.count().compute() If you're using the single machine scheduler then do this: from dask.diagnostics import ProgressBar ProgressBar().register() http://dask.pydata.org/en/latest/diagnostics-local.html If you're using the distributed scheduler then do this: from dask.distributed import progress result = df.id.count.persist() progress(result) Or just use

GitHub上最全的机器学习工具手册

十年热恋 提交于 2019-11-30 09:37:50
近日在Github上发现了一份不错的学习清单,关于Python 在数据科学方面使用库的速查表。 ( Github地址 :https://github.com/FavioVazquez/ds-cheatsheets) 这份速查表包含了 Pandas、Jupyter、SQL、Dask 等十个模块的内容。 整理这套完整的数据科学手册的作者是来自墨西哥的 Favio Vázquez。他是一名物理学家和计算工程师,热爱科学、哲学、编程,研究的是宇宙学和大数据。虽然这个项目是些基本的 API 调用,但是用来备忘和速查足以,而且也是作者花了很大的时间和精力才整理出来的 下面一起来看看这份速查表里都有哪些干货: Business Science Business Science Problem Framework (PDF) 地址: https://github.com/businessscience/cheatsheets/blob/master/Business_Science_Problem_Framework.pdf Data Science with Python Workflow (PDF) 地址: https://github.com/business-science/cheatsheets/blob/master/Data_Science_With_Python_Workflow

Writing Dask partitions into single file

梦想与她 提交于 2019-11-30 08:15:41
New to dask ,I have a 1GB CSV file when I read it in dask dataframe it creates around 50 partitions after my changes in the file when I write, it creates as many files as partitions. Is there a way to write all partitions to single CSV file and is there a way access partitions? Thank you. Short answer No, Dask.dataframe.to_csv only writes CSV files to different files, one file per partition. However, there are ways around this. Concatenate Afterwards Perhaps just concatenate the files after dask.dataframe writes them? This is likely to be near-optimal in terms of performance. df.to_csv('/path

使用Airflow来调度Data Lake Analytics的任务

≡放荡痞女 提交于 2019-11-30 06:03:28
今天我们来介绍一下使用Airflow来调度 Data Lake Analytics (后面简称DLA)的任务执行。DLA作为一个数据湖的解决方案, 客户有每天周期性的调度一些任务从DLA查询数据回流到业务系统的需求。因为DLA兼容 MySQL的协议,因此所有支持MySQL的协议的调度框架都天然支持DLA,今天就来介绍一下使用业界著名的 Apache Airflow 来调度DLA的作业。 大致步骤如下: 购买一个ECS用来运行Airflow 安装Airflow 添加DLA的DB Connection 开发任务脚本 购买ECS并进行配置 购买ECS的详细流程这里就不一一罗列了,非常的简单,按照 官方的购买流程 可以分分钟完成,需要注意的几点这里说一下: 购买的ECS的Region要和你的数据所在Region(其实也就是你开通DLA的 Region 保持一致)。 购买的ECS需要开通外网访问权限,因为Airflow的一些网页控制台需要通过外网来访问。 ECS购买好之后记得在安全组里面放行入方向的80端口,因为下面要安装的Airflow有web页面,我们需要通过80端口进行访问,如下图: 同时记录下这个ECS的外网地址: 安装Airflow Airflow是一个Python写的软件,因此我们是通过Python的Package Manager:pip来安装的,因为我们要使用MySQL

simple dask map_partitions example

最后都变了- 提交于 2019-11-30 04:55:19
问题 I read the following SO thead and now am trying to understand it. Here is my example: import dask.dataframe as dd import pandas as pd from dask.multiprocessing import get import random df = pd.DataFrame({'col_1':random.sample(range(10000), 10000), 'col_2': random.sample(range(10000), 10000) }) def test_f(col_1, col_2): return col_1*col_2 ddf = dd.from_pandas(df, npartitions=8) ddf['result'] = ddf.map_partitions(test_f, columns=['col_1', 'col_2']).compute(get=get) It generates the following

Dask equivalent to Pandas replace?

≯℡__Kan透↙ 提交于 2019-11-29 22:34:55
问题 Something I use regularly in pandas is the .replace operation. I am struggling to see how one readily performs this same operation on a dask dataframe? df.replace('PASS', '0', inplace=True) df.replace('FAIL', '1', inplace=True) 回答1: You can use mask: df = df.mask(df == 'PASS', '0') df = df.mask(df == 'FAIL', '1') Or equivalently chaining the mask calls: df = df.mask(df == 'PASS', '0').mask(df == 'FAIL', '1') 回答2: If anyone would like to know how to replace certain values in a specific column

How do I stop a running task in Dask?

假装没事ソ 提交于 2019-11-29 15:27:44
When using Dask's distributed scheduler I have a task that is running on a remote worker that I want to stop. How do I stop it? I know about the cancel method, but this doesn't seem to work if the task has already started executing. If it's not yet running If the task has not yet started running you can cancel it by cancelling the associated future future = client.submit(func, *args) # start task future.cancel() # cancel task If you are using dask collections then you can use the client.cancel method x = x.persist() # start many tasks client.cancel(x) # cancel all tasks If it is running

How do I change rows and columns in a dask dataframe?

烂漫一生 提交于 2019-11-29 13:48:58
There are few issues I am having with Dask Dataframes. lets say I have a dataframe with 2 columns ['a','b'] if i want a new column c = a + b in pandas i would do : df['c'] = df['a'] + df['b'] In dask I am doing the same operation as follows: df = df.assign(c=(df.a + df.b).compute()) is it possible to write this operation in a better way, similar to what we do in pandas? Second question is something which is troubling me more. In pandas if i want to change the value of 'a' for row 2 & 6 to np.pi , I do the following df.loc[[2,6],'a'] = np.pi I have not been able to figure out how to do a