Integer index labels using Int64Index and RangeIndex

The Int64Index represents an immutable array of 64-bit integers that map to values. Until more recent versions of pandas, this was the default index type when an index was not specified or integers are used as seen in the following code snippet:

Using this index, lookups of rows in the DataFrame are highly efficient as they are performed using a contiguous in-memory array.

Recent versions of pandas added the RangeIndex as an optimization of Int64Index. It has the ability to represent an integer-based index that starts at a specific integer value, has an end integer value, and can also have a step specified.

This use of start, stop, and step was such a common pattern that it warranted adding its own subclass to pandas. By using these three values, memory can be conserved and the execution time is in the same order as in an Int64Index.

RangeIndex has become the default index for pandas objects. This is demonstrated by the following, which creates a range of integer values defaulting to a RangeIndex.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset