Skip to main content
`Ctrl`+`K`

# pandas.RangeIndex.from_range

classmethod RangeIndex.from_range(data, name=None, dtype=None)

  Create `pandas.RangeIndex` from a `range` object.

  This method provides a way to create a `pandas.RangeIndex` directly from a Python `range` object. The resulting `RangeIndex` will have the same start, stop, and step values as the input `range` object. It is particularly useful for constructing indices in an efficient and memory-friendly manner.

  Parameters:
    data range

      The range object to be converted into a RangeIndex.

    name str, default None

      Name to be stored in the index.

    dtype Dtype or None

      Data type for the RangeIndex. If None, the default integer type will be used.

  Returns:
    RangeIndex

  See also

  `RangeIndex`

    Immutable Index implementing a monotonic integer range.

  `Index`

    Immutable sequence used for indexing and alignment.

  Examples

      >>> pd.RangeIndex.from_range(range(5))
      RangeIndex(start=0, stop=5, step=1)

      >>> pd.RangeIndex.from_range(range(2, -10, -3))
      RangeIndex(start=2, stop=-10, step=-3)