是熊猫的虫子吗?这是代码:
In [5]: def test_empty(fname, format):
...: df = pd.DataFrame(index=pd.Index([], name='INDEX'),
...: columns=pd.Index(['A', 'B'], name='COL')).astype({'A': int, 'B': float})
...: print('df to write: \n%s\ndtypes: \n%s' % (df, df.dtypes))
...: with pd.HDFStore(fname, 'w') as writer:
...: writer.put('/data', df, format=format)
...: with pd.HDFStore(fname, 'r') as reader:
...: print('Store keys: %s' % reader.keys())
...: dat = reader.get('/data')
...: print('df read: \n%s\ndtypes: \n%s' % (dat, dat.dtypes))
...:
In [6]: test_empty('f:/empty.h5', 'f')
df to write:
Empty DataFrame
Columns: [A, B]
Index: []
dtypes:
A int32
B float64
dtype: object
Store keys: ['/data']
df read:
Empty DataFrame
Columns: [A, B]
Index: []
dtypes:
A int32
B float64
dtype: object
In [7]: test_empty('f:/empty.h5', 't')
df to write:
Empty DataFrame
Columns: [A, B]
Index: []
dtypes:
A int32
B float64
dtype: object
Store keys: []
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-7-c15e991bdd29> in <module>()
----> 1 test_empty('f:/empty.h5', 't')
<ipython-input-5-6b867bc311dc> in test_empty(fname, format)
7 with pd.HDFStore(fname, 'r') as reader:
8 print('Store keys: %s' % reader.keys())
----> 9 dat = reader.get('/data')
10 print('df read: \n%s\ndtypes: \n%s' % (dat, dat.dtypes))
11
C:\Anaconda3\lib\site-packages\pandas\io\pytables.py in get(self, key)
691 group = self.get_node(key)
692 if group is None:
--> 693 raise KeyError('No object named %s in the file' % key)
694 return self._read_group(group)
695
KeyError: 'No object named /data in the file'
我的蟒蛇环境:
In [8]: pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.20.2
pytest: 3.1.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.1
xarray: None
并且有一个已关闭的错误可能与此相关:https ://github.com/pandas-dev/pandas/issues/1707