是否可以使用F# Deedle直接读取压缩的CSV文件,就像Pandas中的read_csv
函数一样?如果不可能,那么是否可以使用CSV类型提供程序来实现?
open ICSharpCode.SharpZipLib.Zip
open System.IO
open Deedle
[<EntryPoint>]
let main argv =
use fs = new FileStream(@"mycsv.zip", FileMode.Open, FileAccess.Read)
use zip = new ZipFile(fs)
use csv = zip.GetInputStream(0L)
let frame = Frame.ReadCsv(csv)
open System.IO.Compression
open System.IO
let zipfile = @"C:\tmp\zipFile1.zip"
let unzip (zipfile:string) =
let zipf = new FileStream(zipfile,FileMode.Open,FileAccess.Read)
let zip = new ZipArchive(zipf)
zip
let unzipFile = unzip zipfile
let stream = new StreamReader(unzipFile.GetEntry("zipFile1.csv").Open())
let txt = stream.ReadToEnd()
//string * string -> StreamReader
let getFromZip(entry,zip) =
ZipFile.OpenRead(zip)
|> (fun x -> x.GetEntry(entry))
|> (fun x -> new StreamReader(x.Open()))
您可能还需要引用System.IO.Compression.FileSystem
,但不需要打开它。