我正在尝试将pandas DataFrame导出到hdf5文件。具有以下结构的DataFrame。
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4 entries, 0 to 3
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 a 4 non-null float64
1 b 4 non-null float64
2 c 4 non-null float64
3 d 4 non-null object
dtypes: float64(3), object(1)
memory usage: 256.0+ bytes
在d列中,我确实将某些文件路径存储为类型。<class 'pathlib.WindowsPath'>
如果我这样调用to_hdf()函数,df.to_hdf(r'C:\data\test.h5', mode='w', key=key,format='table', data_columns=True)
我将收到以下错误。
File "C:\py36_4\lib\site-packages\pandas\io\pytables.py", line 4800, in _maybe_convert_for_string_atom
for i in range(len(block.shape[0])):
TypeError: object of type 'int' has no len()
如果我跳过列d,则导出到hdf5的工作正常。因此,这似乎是列d和使用的类型'<class 'pathlib.WindowsPath'>
'?
我无法确认您的观察。熊猫和表的最新版本现在支持pathlib Path的序列化。也许你应该
pip install --upgrade pandas tables