pandas.RangeIndex#
- class pandas.RangeIndex(start=None, stop=None, step=None, dtype=None, copy=False, name=None)[源代码]#
实现单调整数范围的不可变 Index。
RangeIndex 是 Index 的一个节省内存的特例,仅限于表示具有 64 位 dtype 的单调范围。在某些情况下使用 RangeIndex 可能会提高计算速度。
这是 DataFrame 和 Series 在用户未提供显式索引时使用的默认索引类型。
- Parameters:
- startint (默认: 0)、range 或其他 RangeIndex 实例
如果为 int 且未给出 “stop”,则被解释为 “stop”。
- stopint (默认: 0)
- stepint (默认: 1)
- dtypenp.int64
未使用,为了与其他索引类型保持一致而接受。
- copybool,默认 False
未使用,为了与其他索引类型保持一致而接受。
- nameobject, optional
要存储在索引中的名称。
参见
Indexpandas Index 的基类。
Examples
>>> 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)) []
Attributes
Methods
from_range(data[, name, dtype])从
range对象创建pandas.RangeIndex。