问题
Trying to open an HDF5 file with pandas. As long as the file is on my USB drive, it cannot be loaded/found by pandas.
import os
import pandas as pd
table_path = r'C:\User\me\Desktop\test\h5table.h5'
if os.path.exists(table_path):
print('yup, this file exists')
h5table = pd.io.pytables.HDFStore(table_path, mode='r')
This works as expected, the table is loaded into h5table. The h5table.h5 is a copy of the original file which is located on a USB drive. Here's me trying to load the original:
table_path = r'E:\data\h5table.h5'
if os.path.exists(table_path):
print('yup, this file exists')
h5table = pd.io.pytables.HDFStore(table_path, mode='r')
This does not work. The file is apparently found, but the attempt to open it results in:
yup, this file exists
HDF5ExtError: HDF5 error back trace
File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5F.c", line 586, in H5Fopen
unable to open file
File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5Fint.c", line 1236, in H5F_open
unable to open file: time = Fri Feb 23 16:02:48 2018, name = 'E:\eit-cps-hii\2017\océ\data\dfki_SCS931000105.h5', tent_flags = 0
File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5FD.c", line 809, in H5FD_open
open failed
File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5FDsec2.c", line 346, in H5FD_sec2_open
unable to open file: name = 'E:\data\h5table.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
End of HDF5 error back trace
Unable to open/create file 'E:\data\h5table.h5'
I have experimented with different path formats, all of them work for the file on C:, none of them for the file on E:.
table_path = 'E:/data/h5table.h5'
table_path = 'E:/data/h5table.h5'.replace('/', os.sep)
table_path = os.path.join('E:', 'data', 'h5table.h5')
Here's the fun part. The drive is a Samsung Portable SSD T3, formatted exFAT. If the file is located on another USB drive, a Samsung Portable SSD T5, formatted NTFS, it can be loaded just fine, like on C:. A problem with the SSD format, then? However,
testfile = 'E:/data/test.txt'
with open(testfile) as testtxt:
for line in testtxt:
print(line)
goes through without error and prints the text file's content line by line.
Moving the file is an option but not preferable. It is not the only one, in fact there are gigabytes of data on the USB drive which is why it is used to store the stuff in the first place. Reformatting is not possible either, as the drive is used for file exchange between Mac and Windows. By the way: opening the HDF5 files on the drive with pandas on the Mac is no problem at all.
How can I open the HDF5 files on their original drive? Bonus: why does it not work, anyway?
来源:https://stackoverflow.com/questions/48951166/pandas-wont-open-hdf5-files-on-a-usb-drive-under-windows