How to change index dtype of pandas DataFrame to int32?

后端 未结 3 667
甜味超标
甜味超标 2020-12-11 03:47

A default dtype of DataFrame index is int64 and I would like to change it to int32.

I tried changing it with pd.DataFrame.set_index and Num

3条回答
  •  不知归路
    2020-12-11 04:29

    Not sure this is something worth doing in practice, but the following should work:

    class Int32Index(pd.Int64Index):
        _default_dtype = np.int32
    
        @property
        def asi8(self):
            return self.values
    
    i = Int32Index(np.array([...], dtype='int32'))
    

    (from here)

提交回复
热议问题