Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I'm trying to unzip a csv file and pass it into pandas so I can work on the file.

The code I have tried so far is:

import requests, zipfile, StringIO

r = requests.get('http://data.octo.dc.gov/feeds/crime_incidents/archive/crime_incidents_2013_CSV.zip')

z = zipfile.ZipFile(StringIO.StringIO(r.content))

crime2013 = pandas.read_csv(z.read('crime_incidents_2013_CSV.csv'))

After the last line, although python is able to get the file, I get a "does not exist" at the end of the error.

Can someone tell me what I'm doing incorrectly?

1 Answer

0 votes
by (41.4k points)

Here is an implementation of the read_csv methods to read a zipped or a tar.gz file into pandas dataframe:

df = pd.read_csv('filename.tar.gz', compression='gzip', header=0, sep=',', quotechar='"')

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in Python by Eresh Kumar (45.3k points)
0 votes
1 answer

Browse Categories

...