简体   繁体   English

Zip 加载后文件丢失

[英]File Missing after Zip Load

I am trying to import a CSV file as a Pandas data frame.我正在尝试将 CSV 文件导入为 Pandas 数据框。 The files are included in a larger Zip file.这些文件包含在一个更大的 Zip 文件中。 Below is my code:下面是我的代码:

import tensorflow as tf
from tensorflow import keras
import pandas as pd
import zipfile

DataURL = "file:///c:/Users/MMoynihan/Desktop/TensorFlow/DNN_Dataset/SIM_IMGS.zip"
TagURL = "file:///c:/Users/MMoynihan/Desktop/TensorFlow/DNN_Dataset/SIM_TAGS.zip"
TagName1 = 'Sim_TAG0_2021-08-13-18-52.csv'

data_for_processing = keras.utils.get_file('plots', DataURL)
tags_for_processing = keras.utils.get_file('tags', DataURL)

zf = zipfile.ZipFile(tags_for_processing)
df = pd.read_csv(zf.open(TagName1))

For whatever reason, the tagged file is not listed as being part of the larger Zip file.无论出于何种原因,标记文件未作为较大的 Zip 文件的一部分列出。

raise KeyError(
KeyError: "There is no item named 'Sim_TAG0_2021-08-13-18-52.csv' in the archive"

I tested 4 or 5 different file names that I know are present, but none of these came up as listed in the zip.我测试了 4 或 5 个我知道存在的不同文件名,但没有一个像 zip 中列出的那样出现。

==== ====

I have a similar problem accessing the image files.我在访问图像文件时遇到类似的问题。

import tensorflow as tf
from tensorflow import keras
import pandas as pd
import zipfile

DataURL = "file:///c:/Users/MMoynihan/Desktop/TensorFlow/DNN_Dataset/SIM_IMGS.zip"
TagURL = "file:///c:/Users/MMoynihan/Desktop/TensorFlow/DNN_Dataset/SIM_TAGS.zip"

TagTest = 'Sim_TAG7_2021-08-13-18-52.csv'
ImageTest = 'Sim_Image1_2021-08-13-18-52.png'

IMG_processing = keras.utils.get_file('plots', DataURL)
TAGS_processing = keras.utils.get_file('tags', DataURL)

archive = zipfile.ZipFile(IMG_processing, 'r')
imgdata = archive.read(ImageTest)

Below are the errors:以下是错误:

Raise KeyError(KeyError: "There is no item named 'Sim_Image1_2021-08-13-18-52.png' in the archive"

I solved this issue.我解决了这个问题。 The filename must include the zip folder in which it resides.文件名必须包括它所在的 zip 文件夹。 in this case:在这种情况下:

TagTest = 'SIM_TAGS/Sim_TAG7_2021-08-13-18-52.csv'
ImageTest = 'SIM_IMGS`/Sim_Image1_2021-08-13-18-52.png'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 zip 存档中加载 json 文件 - Load json file from within a zip archive 从 zip 文件将数据加载到 pandas dataframe 中 - Load data into pandas dataframe from zip file 如何加载存储在zip文件中的一组图像? - How to load a set of images stored in a zip file? 是否可以从zip加载PyQT UIC文件 - Is it possible to load a PyQT UIC file from a zip 从 Google Colab 中的 GitHub 加载.zip 文件 - Load .zip file from GitHub in Google Colab 如何使用 pyscript 加载 zip 文件并保存到虚拟文件系统中 - How to load a zip file with pyscript and save into the virtual file system 解析参数“--zip-file”时出错:无法加载参数文件 fileb://app.zip:[Errno 2] 没有这样的文件或目录:“app.zip” - Error parsing parameter '--zip-file': Unable to load paramfile fileb://app.zip: [Errno 2] No such file or directory: 'app.zip' Python tflearn:使用包含图像的文件夹加载一个zip文件 - Python tflearn: Load a zip file with folders containing images 熊猫:如何加载包含多个txt文件的zip文件? - Pandas: how to load a zip file containing multiple txt files? 使用 Panda 将解码的 zip 文件转换为 .txt 文件时出错(解码文件在开始时缺少 '\\t') - Error when converting decoded zip file to .txt file using panda (decoded file missing '\t' at start)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM