reading gzipped csv file in python 3

You are opening the file in binary mode (which is the default for gzip).

Try instead:

import gzip
import csv
f = gzip.open(filename, mode='rt')
csvobj = csv.reader(f,delimiter = ',',quotechar="'")

too late, you can use datatable package in python

import datatable as dt
df = dt.fread(filename)
df.head()

Default mode for gzip.open is rb, if you wish to work with strs, you have to specify it extra:

f = gzip.open(filename, mode="rt")

OT: it is a good practice to write I/O operations in a with block:

with gzip.open(filename, mode="rt") as f:

Tags:

Python

Csv

Gzip