HDFStore无法以表格格式保存空数据帧

时间:2017-07-23 05:05:02

标签: pandas hdfstore

这是大熊猫的错误​​吗? 这是代码:

categoryClicked(category){
    this.props.categoryPressed(category);
}

我的python env:

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'

并且有一个封闭的错误可能与此相关:https://github.com/pandas-dev/pandas/issues/1707

0 个答案:

没有答案