S.V*_*S.V 5 python pytables dataframe pandas hdf
如何将具有可为空整数数据类型的 pandas DataFrame 保存到“表”格式的 HDF 文件中?
# input data
import pandas as pd, numpy as np
df = pd.DataFrame(index=list(range(2)), data={'x':[np.uint8(1)]*2}, dtype='UInt8')
df.to_hdf('temp.h5', 'data', format='table')
# raises the following exceptions:
# AttributeError: module 'tables' has no attribute 'Uint8Col'
# Exception: cannot find the correct atom type -> [dtype->UInt8,items->Index(['x'], dtype='object')] module 'tables' has no attribute 'Uint8Col'
# 'fixed' format does not work either:
df.to_hdf('temp.h5', 'data', format='fixed')
# raises the following exception:
# TypeError: objects of type ``IntegerArray`` are not supported in this context, sorry; supported objects are: NumPy array, record or scalar; homogeneous list or tuple, integer, float, complex or bytes
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
670 次 |
| 最近记录: |