Int32Index type?

瀏覽次數:26 次
跳到第一則未讀訊息

Nick Eubank

未讀,
2017年4月13日 下午3:35:532017/4/13
收件者:pyd...@googlegroups.com
Hi All,

Is there a way to compress an Int64Index into a Int32Index? I'm a little tight on memory for a very long, narrow DataFrame, and it'd be a huge help to compress. But no luck when I try:

    df.index = df.index.astype('Int32Index')

or 

    df.columnA = df.columnA.astype('int32')
    df = df.set_index('columnA')

Thanks!

Nick

Pietro Battiston

未讀,
2017年4月13日 下午4:15:492017/4/13
收件者:pyd...@googlegroups.com
Il giorno gio, 13/04/2017 alle 19.35 +0000, Nick Eubank ha scritto:
> Hi All,
>
> Is there a way to compress an Int64Index into a Int32Index?

I'm afraid this was supported only partially, and was finally dropped
last year.

But although horribly untested, I suspect that

class Int32Index(pd.Int64Index):
_default_dtype = np.int32


i = Int32Index(np.array([...], dtype='int32'))

might do.

Pietro

Joris Van den Bossche

未讀,
2017年4月13日 下午5:18:352017/4/13
收件者:PyData
Depending on the use case, a RangeIndex could save memory (but of course much more limited)


--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick Eubank

未讀,
2017年4月14日 上午11:43:482017/4/14
收件者:PyData
Great, thanks everyone! Will give those both a shot. 


On Thursday, April 13, 2017 at 2:18:35 PM UTC-7, Joris Van den Bossche wrote:
Depending on the use case, a RangeIndex could save memory (but of course much more limited)
2017-04-13 22:15 GMT+02:00 Pietro Battiston <m...@pietrobattiston.it>:
Il giorno gio, 13/04/2017 alle 19.35 +0000, Nick Eubank ha scritto:
> Hi All,
>
> Is there a way to compress an Int64Index into a Int32Index?

I'm afraid this was supported only partially, and was finally dropped
last year.

But although horribly untested, I suspect that

class Int32Index(pd.Int64Index):
    _default_dtype = np.int32


i = Int32Index(np.array([...], dtype='int32'))

might do.

Pietro

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
回覆所有人
回覆作者
轉寄
0 則新訊息