下载CSV问题Julia - ArgumentError:符号名称可能不包含



我试图从Julia使用下载和csv的url中获得一个简单的csv文件而没有成功。这是我目前所做的:

using Downloads, CSV
url = "https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv"
f = Downloads.download(url)
df = CSV.read(f, DataFrame)

但是我得到以下错误:ArgumentError:符号名可能不包含

我试过使用normalizenames,但也没有成功:

f = Downloads.download(url)
df = CSV.File(f, normalizenames=true)

但我得到无效utf - 8作为错误信息字符串

当我简单地下载文件并以CSV格式从我的PC上获得它时。read I get no error .

服务器使用Content-Encoding: gzip提供该文件,即传输的数据被压缩,并且期望客户端解压它。您可以在命令行上自己尝试一下,curl默认不解压:

$ curl https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv                                                             [9:40:49]
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.

但是如果你传递了--compressed标志:

$ curl --compressed https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv
"time","Nile"
1871,1120
1872,1160
1873,963
[...]

下载。jl使用libcurl,我在下载中找不到太多关于处理压缩内容的内容。杰库。

要解决这个问题,您可以升级到v0.9.4的CSV。

如果更新不是一个选项,你可以使用CodecZlib。jl手动:

using Downloads, CSV, DataFrames, CodecZlib
url = "https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv"
f = Downloads.download(url)
df = open(fh -> CSV.read(GzipDecompressorStream(fh), DataFrame), f)

最新更新