Skip to main content

Python Pandas: RangeIndex

In Pandas RangeIndex is a memory-saving special case of Int 64 Index which is limited for only representing monotonic ranges.
By using rangeindex we can improve computing speed.

It is a default index type that can be used for DataFrame or Series when there is no explicit index which is provided by the user.

Syntax

class pandas.RangeIndex(start=None, stop=None, step=None, dtype=None, copy=False, name=None)

Parameters:

  •  start: It is by default 0. It can be int or rangeindex or other RangeIndex instance. If int and "stop" is not given, interpreted as “stop” instead.
  • stop: It is by default 0. It can be int.
  • step: It is by default 1. It can be int.
  • dtype: It is used for homogeneity with other types of index
  • copy: It is also used for homogeneity with other types of index
  • name: It is the name that can be stored with the index

Example

import pandas as pd
df=pd.DataFrame({'a':range(1,11)})
print(df)

Output:

  a
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
df.index = pd.RangeIndex(start=10, stop=100, step=10)
print(df)

Output:

     a 
10   1 
20   2 
30   3 
40   4 
50   5 
60   6 
70   7 
80   8 
90   9 
100 10
Submitted by devanshi.srivastava on November 16, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.