最新のパンダリリース(0.8)でset_indexは劇的に変化しましたか?期待どおりに機能させるのに問題があります。
私の最初の試みは'id'にインデックスを設定しようとしました
ipdb> merged2['id']
16 130809
25 130687
32 130686
9 41736
22 131913
7 130691
33 129993
13 130680
28 134295
29 130708
ipdb> merged2.set_index('id')
*** KeyError: 0
ipdb> [type(i) for i in merged2['id']]
[<type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>]
現在のインデックスはintです:
ipdb> merged2.index
Int64Index([16, 25, 32, 9, 22, 7, 33, 13, 28, 29])
ipdb> [type(i) for i in merged2.index]
[<type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>, <type 'numpy.int64'>]
回避策は、新しいインデックスを作成しようとしました。
ndx=range(len(merged2))
[type(i) for i in ndx]
[<type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>]
ipdb> merged2.set_index(ndx)
*** KeyError: 'no item named 0'
最後に、intが機能するようにインデックスをマッピングします。
merged2['id']=map(lambda x: int(x), merged2['id']
merged2.set_index('id')
私が間違っていることについての考え?