【问题标题】:Extract data from .gz file从 .gz 文件中提取数据
【发布时间】:2022-01-03 21:41:04
【问题描述】:

我正在尝试打开一个 .gz 文件(它只是 .gz,而不是 .log.gz 或其他任何文件),但逐行读取文件只会显示乱码。它应该有传感器数据。

这是我的代码:

import gzip

with gzip.open('data.gz','r') as fin:        
    for line in fin:        
        print('got line', line)

这是一个输出示例:

b'\x80\x04\x95\x90\x01\x00\x00\x00\x00\x00\x00\x8c\x1bsklearn.preprocessing._data\x94\x8c\x0eStandardScaler\x94\x93\x94)\x81\x94}\x94(\x8c\twith_mean\x94\x88\x8c\x08with_std\x94\x88\x8c\x04copy\x94\x88\x8c\x0en_features_in_\x94K\x08\x8c\x0fn_samples_seen_\x94\x8c\x15numpy.core.multiarray\x94\x8c\x06scalar\x94\x93\x94\x8c\x05numpy\x94\x8c\x05dtype\x94\x93\x94\x8c\x02i8\x94K\x00K\x01\x87\x94R\x94(K\x03\x8c\x01<\x94NNNJ\xff\xff\xff\xffJ\xff\xff\xff\xffK\x00t\x94bC\x08\xae\x0b\x00\x00\x00\x00\x00\x00\x94\x86\x94R\x94\x8c\x05mean_\x94\x8c\x13joblib.numpy_pickle\x94\x8c\x11NumpyArrayWrapper\x94\x93\x94)\x81\x94}\x94(\x8c\x08subclass\x94h\r\x8c\x07ndarray\x94\x93\x94\x8c\x05shape\x94K\x08\x85\x94\x8c\x05order\x94\x8c\x01C\x94\x8c\x05dtype\x94h\x0f\x8c\x02f8\x94K\x00K\x01\x87\x94R\x94(K\x03h\x13NNNJ\xff\xff\xff\xffJ\xff\xff\xff\xffK\x00t\x94b\x8c\n'
b'allow_mmap\x94\x88ub*\xd4\xff\xe6\xbd\rE@\x15\xd1=A5\xdfg@\x0f\x7fv\x94\xabjg@\x04?\xf0\x03?0^@v\x94\xab\xda\xb5\xb6E@\x9bz\xec\xdd\x90\x9e?@\x13\xd7\xa8J\x94\x92;@*\x1f\xc6\xfd\xba$7@\x95&\x00\x00\x00\x00\x00\x00\x00\x8c\x04var_\x94h\x1b)\x81\x94}\x94(h\x1eh h!K\x08\x85\x94h#h$h%h(h*\x88ub\x8f\x16F\x8b\xed\n'
b'T@\x01^\xd6u\xfd\x94\xa9@Z\xae\xc2d\xb0\x05\x9a@\xe7\xbb\xeeu.$\x85@~\xd7\xe2\xe7_@F@\xb0$HdS\x17F@*\xa8\x07o\x16]}@\x1e\xba\xc0\xc8r]<@\x95(\x00\x00\x00\x00\x00\x00\x00\x8c\x06scale_\x94h\x1b)\x81\x94}\x94(h\x1eh h!K\x08\x85\x94h#h$h%h(h*\x88ub\x8fDh\n'
b'Z\xe8!@E\xaa1\xf0\x91\x9cL@Q\xecq~\xa0gD@\x13m$\x9e\x92\x02:@\xe9>L\x19(\xaf\x1a@DZ\xf9\xbd\x7f\x96\x1a@~\x014y\xdf\xac5@y\xa3\xc0X\xb4M\x15@\x95\x1f\x00\x00\x00\x00\x00\x00\x00\x8c\x10_sklearn_version\x94\x8c\x060.24.1\x94ub.'

【问题讨论】:

标签: python gzip


【解决方案1】:

你需要unpickle解压的结果来重构保存的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多