如何在 jupyter notebook 中压缩所有输出(*.csv 和 *.tiff)

How to zip all outputs (*.csv and *.tiff) in jupyter notebook

我在 jupyter notebook (python3.7.10) 中使用此命令 ! zip -r results.zip . -i *.csv *.pdf 来压缩所有输出文件。但是,它显示 'zip' is not recognized as an internal or external command, operable program or batch file. 任何人都可以提出我想念的内容吗?

我认为你正在尝试使用,os.system():
如果您使用 linux

import os 
os.system("zip -r results.zip . -i *.csv *.pdf")
#OR
import subprocess
subprocess.Popen("zip -r results.zip . -i *.csv *.pdf")

如果您没有使用 linux,在 windows 中。有一个名为 zipfile 的库,你可以使用它:

from zipfile import ZipFile
import os

filesname=os.listdir("<path or empty") # Or you can alternately use glob inside `with` ZipFile
# Empty means working folder 

with ZipFile('output.zip', 'w') as myzip:
    for file in files:
        if file.endswith(".csv") and file.endswith(".pdf"):
            myzip.write(file)