Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read a gzipped CSV file in Julia?

Tags:

julia

I have tried many libraries, but it seems that I cannot get the types to match.

Typical attempt:

using SomeLib, CSV
fh = SomeLib.open("gzipped_file.gz")
CSV.read(fh) # error

Example:

using CodecZlib
CSV.read(GzipDecompressorStream(open("gzipped_file.gz")))
# ERROR: MethodError: no method matching position(::TranscodingStreams.TranscodingStream{GzipDecompressor,IOStream})
like image 808
The Unfun Cat Avatar asked Oct 01 '18 12:10

The Unfun Cat


People also ask

What is a Gzipped file?

GZIP, short for GNU Zip, is a compression/decompression format developed as part of a larger project to create a free software alternative to UNIX in the 1980s. This open source compression format does not support archiving, so it is used to compress single files. GZIP produces zipped files with the . gz extension.

How do I read a gzip file?

Launch WinZip from your start menu or Desktop shortcut. Open the compressed file by clicking File > Open. If your system has the compressed file extension associated with WinZip program, just double-click on the file.


1 Answers

In the meantime you can use CSVFiles.jl:

using CSVFiles, DataFrames, FileIO

open("yourfile.csv.gz") do io
    load(Stream(format"CSV", GzipDecompressorStream(io))) |> DataFrame
end
like image 77
Bogumił Kamiński Avatar answered Oct 03 '22 19:10

Bogumił Kamiński