cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

how to zip a dataframe

amitdatabricksc
New Contributor II

how to zip a dataframe so that i get a zipped csv output file. please share command. it is only 1 dataframe involved and not multiple. 

4 REPLIES 4

Ryan_Chynoweth
Esteemed Contributor

If you are using pyspark you can do something like the following:

df.coalesce(1).write.option("compression","gzip").csv("path")
 

Note the coalesce will reduce the number of partitions so that it is saved as a single file. In addition to gzip you can use "bzip2", "lz4", "snappy", and "deflate".

If you are not using pyspark and are using pandas then you can use the pandas compression option which can be found here.

Thanks. I have 19 files as csv in s3 and would like to zip all 19 csv files as one zip file. Please advise on this,

amitdatabricksc
New Contributor II

if my path is my local directory then how should i write it

when i do df.coalesce(1).write.option("compression","gzip").csv("C:/Users/ag") i am getting an error.

Also, can u provide an example for output path to blob storage folder

-werners-
Esteemed Contributor III

writing to a local directory does not work.

See this topic:

https://community.databricks.com/s/feed/0D53f00001M7hNlCAJ

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group