pandas.RangeIndex.from_range#
- classmethod RangeIndex.from_range(data, name=None, dtype=None)[source]#
Create
pandas.RangeIndex
from arange
object.This method provides a way to create a
pandas.RangeIndex
directly from a Pythonrange
object. The resultingRangeIndex
will have the same start, stop, and step values as the inputrange
object. It is particularly useful for constructing indices in an efficient and memory-friendly manner.- Parameters:
- datarange
The range object to be converted into a RangeIndex.
- namestr, default None
Name to be stored in the index.
- dtypeDtype 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)