如何在HDFStore.append中正确设置min_itemsize?

时间:2015-10-18 20:13:40

标签: python pandas hdf5

我已阅读以下Q& As:

How to specify min_itemsize for an index column

Pandas pytable: how to specify min_itemsize of the elements of a MultiIndex

但仍然不能让我的玩具示例工作:

with pd.HDFStore('teststore.h5') as store:
    chunk = pd.DataFrame({"V1":["a","b","c","d","e"], "data":np.arange(5)}).set_index(["V1"])
    store.append("gr1", chunk, min_itemsize={chunk.index.name: 32 })

    chunk = pd.DataFrame({"V1":["aaaah!!!"], "data": 3}).set_index(["V1"])
    store.append("gr1", chunk, min_itemsize={chunk.index.name: 32 })

返回:ValueError: min_itemsize has the key [V1] which is not an axis or data_column,而:

with pd.HDFStore('teststore.h5') as store:
    chunk = pd.DataFrame({"V1":["a","b","c","d","e"], "data":np.arange(5)}).set_index(["V1"])
    store.append("gr1", chunk, min_itemsize={"index": 32 })

    chunk = pd.DataFrame({"V1":["aaaah!!!"], "data": 3}).set_index(["V1"])
    store.append("gr1",chunk, min_itemsize={"index": 32 })

返回:

ValueError: Trying to store a string with len [8] in [index] column but
this column has a limit of [1]!
Consider using min_itemsize to preset the sizes on these columns

什么是正确/有效的方式?

0 个答案:

没有答案