Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Pandas - Display the value of the start parameter of RangeIndex
To display the value of the start parameter of RangeIndex, use the index.start property in Pandas. RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges that can improve computing performance.
What is RangeIndex?
RangeIndex represents a monotonic integer range similar to Python's range() function. It stores only the start, stop, and step values instead of the entire sequence, making it memory-efficient for large ranges.
Creating a RangeIndex
You can create a RangeIndex by specifying start, stop, step, and an optional name ?
import pandas as pd
# Create a range index with start, stop and step
index = pd.RangeIndex(start=5, stop=20, step=2, name="data")
# Display the RangeIndex
print("RangeIndex...")
print(index)
RangeIndex... RangeIndex(start=5, stop=20, step=2, name='data')
Accessing the Start Parameter
Use the start property to get the starting value of the RangeIndex ?
import pandas as pd
# Create a range index
index = pd.RangeIndex(start=5, stop=20, step=2, name="data")
# Display the start parameter value
print("RangeIndex start value:")
print(index.start)
# You can also access other parameters
print(f"Stop value: {index.stop}")
print(f"Step value: {index.step}")
print(f"Name: {index.name}")
RangeIndex start value: 5 Stop value: 20 Step value: 2 Name: data
Complete Example
Here's a comprehensive example showing RangeIndex creation and parameter access ?
import pandas as pd
# Create different RangeIndex objects
index1 = pd.RangeIndex(start=0, stop=10)
index2 = pd.RangeIndex(start=5, stop=20, step=2, name="custom_range")
# Display the indexes and their start values
print("Index 1:", index1)
print("Index 1 start:", index1.start)
print()
print("Index 2:", index2)
print("Index 2 start:", index2.start)
# Convert to list to see actual values
print("\nActual values in index2:", list(index2))
Index 1: RangeIndex(start=0, stop=10, step=1) Index 1 start: 0 Index 2: RangeIndex(start=5, stop=20, step=2, name='custom_range') Index 2 start: 5 Actual values in index2: [5, 7, 9, 11, 13, 15, 17, 19]
Conclusion
Use index.start to access the start parameter of a RangeIndex. RangeIndex is memory-efficient for large sequential ranges and provides easy access to its defining parameters through properties.
