まず、2 次元の階層インデックスを持つシリーズを作成します。それらのインデックス タイプは (pandas.period, numpy.int32) です。
In [265]: import pandas as pd
In [266]: import numpy as 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()
次に、HDFStore を使用してシリーズ (ts1) を保存し、それを (ts2 として) 取得します。
In [271]: with pd.HDFStore(hdf_file, 'w') as store:
...: store['ts'] = ts1
...:
In [272]: with pd.HDFStore(hdf_file, 'r') as store:
...: ts2 = store['ts']
...:
これで、取得したシリーズ (ts2) のインデックスの dtype が整数に変更されました。
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
シリーズを適切に保存する方法はありますか?データを取得した後で型を変更できることはわかっていますが、私は仕事をきれいに行うことを好みます。
pandas 0.16.1 と pyhon 2.7.7 (Anaconda 2.0.1 (64 ビット)) を使用しています。