pandas.RangeIndex#
- class pandas.RangeIndex(start=None, stop=None, step=None, dtype=None, copy=False, name=None)[source]#
实现单调整数范围的不可变 Index。
RangeIndex 是一个节省内存的特殊 Index,它仅限于表示具有 64 位 dtype 的单调范围。在某些情况下,使用 RangeIndex 可能会提高计算速度。
这是 DataFrame 和 Series 在用户未提供显式索引时使用的默认索引类型。
- 参数:
- startint, range, 或其他 RangeIndex 实例,默认为 None
如果为 int 且未给出“stop”,则解释为“stop”。
- stopint,默认为 None
范围的结束值(不包含)。
- stepint,默认为 None
范围的步长。
- dtypenp.int64,默认为 None
未使用,为与其他索引类型的同质性而接受。
- copybool,默认值 False
未使用,为与其他索引类型的同质性而接受。
- nameobject,可选
存储在索引中的名称。
属性
Methods
from_range(data[, name, dtype])从
range对象创建pandas.RangeIndex。另请参阅
索引基础 pandas Index 类型。
示例
>>> list(pd.RangeIndex(5)) [0, 1, 2, 3, 4]
>>> list(pd.RangeIndex(-2, 4)) [-2, -1, 0, 1, 2, 3]
>>> list(pd.RangeIndex(0, 10, 2)) [0, 2, 4, 6, 8]
>>> list(pd.RangeIndex(2, -10, -3)) [2, -1, -4, -7]
>>> list(pd.RangeIndex(0)) []
>>> list(pd.RangeIndex(1, 0)) []