How to unzip gz file using Python How to unzip gz file using Python python python

How to unzip gz file using Python


import gzipimport shutilwith gzip.open('file.txt.gz', 'rb') as f_in:    with open('file.txt', 'wb') as f_out:        shutil.copyfileobj(f_in, f_out)


From the documentation:

import gzipwith gzip.open('file.txt.gz', 'rb') as f:    file_content = f.read()


Maybe you want pass it to pandas also.

with gzip.open('features_train.csv.gz') as f:    features_train = pd.read_csv(f)features_train.head()