How to unzip gz file using Python

后端 未结 6 1853
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 02:37

I need to extract a gz file that I have downloaded from an FTP site to a local Windows file server. I have the variables set for the local path of the file, and I know it ca

6条回答
  •  温柔的废话
    2020-12-01 02:53

    Not an exact answer because you're using xml data and there is currently no pd.read_xml() function (as of v0.23.4), but pandas (starting with v0.21.0) can uncompress the file for you! Thanks Wes!

    import pandas as pd
    import os
    fn = '../data/file_to_load.json.gz'
    print(os.path.isfile(fn))
    df = pd.read_json(fn, lines=True, compression='gzip')
    df.tail()
    

提交回复
热议问题