Python Pandas - Display the value of the stop parameter of RangeIndex

To display the value of the stop parameter of RangeIndex, use the index.stop property in Pandas. RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges, which can improve computing speed in some instances.

What is RangeIndex?

RangeIndex represents a sequence of integers with a start, stop, and step value. It's similar to Python's range() function but optimized for pandas operations ?

import pandas as pd

# Create a RangeIndex with start=10, stop=30, step=2
index = pd.RangeIndex(start=10, stop=30, step=2, name="data")
print("RangeIndex...")
print(index)
RangeIndex...
RangeIndex(start=10, stop=30, step=2, name='data')

Accessing the Stop Parameter

Use the .stop property to retrieve the stop value of the RangeIndex ?

import pandas as pd

index = pd.RangeIndex(start=10, stop=30, step=2, name="data")

# Display the stop parameter value
print("RangeIndex stop value:")
print(index.stop)

# You can also access other parameters
print("\nOther RangeIndex parameters:")
print(f"Start: {index.start}")
print(f"Step: {index.step}")
print(f"Name: {index.name}")
RangeIndex stop value:
30

Other RangeIndex parameters:
Start: 10
Step: 2
Name: data

Practical Example

Here's how you might use RangeIndex with a DataFrame and access its stop parameter ?

import pandas as pd

# Create a DataFrame with RangeIndex
df = pd.DataFrame({
    'values': [100, 200, 300, 400, 500]
}, index=pd.RangeIndex(start=5, stop=15, step=2, name="custom_index"))

print("DataFrame:")
print(df)

print(f"\nIndex stop parameter: {df.index.stop}")
print(f"Index range covers: {df.index.start} to {df.index.stop-1} (step {df.index.step})")
DataFrame:
     values
custom_index        
5       100
7       200
9       300
11      400
13      500

Index stop parameter: 15
Index range covers: 5 to 14 (step 2)

Conclusion

The .stop property provides easy access to the stop parameter of a RangeIndex. This is useful when you need to understand the bounds of your index or perform operations based on the index range.

Updated on: 2026-03-26T16:41:23+05:30

508 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements