Int32Index type?

26 views
Skip to first unread message

Nick Eubank

unread,
Apr 13, 2017, 3:35:53 PM4/13/17
to 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

unread,
Apr 13, 2017, 4:15:49 PM4/13/17
to 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

unread,
Apr 13, 2017, 5:18:35 PM4/13/17
to 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

unread,
Apr 14, 2017, 11:43:48 AM4/14/17
to 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.
Reply all
Reply to author
Forward
0 new messages