- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - How to create a RangeIndex
To create a RangeIndex, use the pandas.RangeIndex() method in Pandas. At first, import the required libraries −
import pandas as pd
RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges. Using RangeIndex may in some instances improve computing speed.
Create a range index with start, stop and step. The name is the name to be stored in the index −
index = pd.RangeIndex(start=10, stop=30, step=2, name="data")
Display the start parameter value −
print("\nRangeIndex start value...\n",index.start)
Display the stop parameter value −
print("\nRangeIndex stop value...\n",index.stop)
Display the step parameter value −
print("\nRangeIndex step value...\n",index.step)
Example
Following is the code −
import pandas as pd # Create a range index with start, stop and step # The name is the name to be stored in the index. index = pd.RangeIndex(start=10, stop=30, step=2, name="data") # Display the RangeIndex print("RangeIndex...\n",index) # Display the start parameter value print("\nRangeIndex start value...\n",index.start) # Display the stop parameter value print("\nRangeIndex stop value...\n",index.stop) # Display the step parameter value print("\nRangeIndex step value...\n",index.step)
Output
This will produce the following output −
RangeIndex... RangeIndex(start=10, stop=30, step=2,name='data') RangeIndex start value... 10 RangeIndex stop value... 30 RangeIndex step value... 2
Advertisements