阅读csv压缩文件在python [英] Reading csv zipped files in python

查看:127
本文介绍了阅读csv压缩文件在python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从压缩的csv文件获取数据。有没有办法做到这一点,而不解压整个文件?

I'm trying to get data from a zipped csv file. Is there a way to do this without unzipping the whole files? If not, how can I unzip the files and read them efficiently?

推荐答案

我使用zipfile模块导入ZIP文件直接yo pandas数据框。
让我们说文件名是intfile,它的zip名为THEZIPFILE。

I used the "zipfile" module to import the ZIP directly yo pandas dataframe. let's say The file name is "intfile" and it's in zip named "THEZIPFILE".

import pandas as pd
import zipfile

zf = zipfile.ZipFile('C:/Users/Desktop/THEZIPFILE.zip') 
df = pd.read_csv(zf.open('intfile.csv'))

这篇关于阅读csv压缩文件在python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆