简体   繁体   中英

How to read the text files in gzip format without unzipping it write that line to excel using python?

Problem Statement : I have a directory with gzip files , and each gzip file contains a text file. I have written a code in such a way that it unzips all the gzip files and then used to read each unzipped text file and then combined that output to one text file, then applied a condition , if that condition meets then it writes to excel. The above process is bit tedious and lengthy. Can anyone please help me out in writing the code where the data is read directly from the txt file which is gzipped and write it contents to excel.

IIUC you can use pandas using first read_csv :

df = read_csv('yourfile.gzip', compression='gzip')

then apply your conditions on df and write back the dataframe to excel using to_excel :

df.to_excel(file.xls)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM