0

How to split a csv file into multiple files using Dask?

The bellow code seems to write to one file only which takes a long time to write the full thing. I believe writing to multiple files will be faster.

import dask.dataframe as ddf
import dask
file_path = "file_name.csv"
df   = ddf.read_csv(file_path)
futs = df.to_csv(r"*.csv", compute=False)
_, l = dask.compute(futs, df.size)
1
  • 2
    Have you considered splitting it using bash? It might be faster. Commented Apr 30, 2019 at 17:00

1 Answer 1

2

I suspect that when you read df you have df.npartitions is just 1.

import dask.dataframe as dd

file_path = "file_name.csv"
df = dd.read_csv(file_path)
# set how many file you would like to have
# in this case 10
df = df.repartition(npartitions=10)
df.to_csv("file_*.csv")

But as far as I can see it's not faster.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.