python - Pandas HDFStore: Saving and Retrieving a Series with Hierarchical Period Index -
i first create series 2 dimensional hierarchical index. index type (pandas.period, numpy.int32)
in [265]: import pandas pd in [266]: import numpy np in [267]: hdf_file = r'f:\test.h5' in [268]: data = np.random.randint(10, size=(7, 3)) in [269]: dates = pd.date_range('1/1/2015', '1/7/2015').to_period('d') in [270]: ts1 = pd.dataframe(data, index = dates, columns = [1, 2, 3]).stack()
then, save series (ts1) using hdfstore , retrieve (as ts2):
in [271]: pd.hdfstore(hdf_file, 'w') store: ...: store['ts'] = ts1 ...: in [272]: pd.hdfstore(hdf_file, 'r') store: ...: ts2 = store['ts'] ...:
now, dtype of index of retrieved series (ts2) has been changed integer:
in [273]: print(ts1) 2015-01-01 1 3 2 8 3 0 2015-01-02 1 2 2 3 3 9 2015-01-03 1 9 2 2 3 2 2015-01-04 1 4 2 5 3 1 2015-01-05 1 2 2 1 3 6 2015-01-06 1 1 2 0 3 8 2015-01-07 1 0 2 6 3 8 dtype: int32 in [274]: print(ts2) 16436 1 3 2 8 3 0 16437 1 2 2 3 3 9 16438 1 9 2 2 3 2 16439 1 4 2 5 3 1 16440 1 2 2 1 3 6 16441 1 1 2 0 3 8 16442 1 0 2 6 3 8 dtype: int32
is there way save series properly? know can change type after retrieve data, prefer job cleanly.
i using pandas 0.16.1 , pyhon 2.7.7 (anaconda 2.0.1 (64-bit))
this not implemented see issue here
save timestamps , convert periods after read back
Comments
Post a Comment