[英]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.