RangeIndex#
- class RangeIndex#
Immutable Index implementing a monotonic integer range.
Example#
import pandasCore as pd
# Create RangeIndex
idx = pd.RangeIndex([1, 2, 3], name='my_index')
print(len(idx)) # 3
Attributes#
Attribute |
Description |
Example |
|---|---|---|
|
Return the dtype object of the underlying data |
|
|
Whether the Index is empty |
|
|
Return if the Index has duplicate values |
|
|
Return boolean if values in the object are monotonically decreasing |
|
|
Return boolean if values in the object are monotonically increasing |
|
|
Return if the Index has unique values |
|
|
Return Index or MultiIndex name |
|
|
Return the number of bytes in the underlying data |
|
|
Number of dimensions of the underlying data, by definition 1 |
|
|
Number of levels |
|
|
Return a tuple of the shape of the underlying data |
|
|
Return the number of elements |
|
|
The value of the start parameter |
|
|
The value of the step parameter |
|
|
The value of the stop parameter |
|
|
Vectorized string functions for Index. |
Construction#
Method |
Description |
Example |
|---|---|---|
|
Create an empty RangeIndex |
Indexing / Selection#
Method |
Description |
Example |
|---|---|---|
|
||
|
Return a new Index of the values selected by the indices |
|
|
Replace values where the condition is False |
Data Manipulation#
Method |
Description |
Example |
|---|---|---|
|
Make new Index with passed list of labels deleted |
|
|
Return index with requested level(s) removed |
|
|
Make new Index inserting new item at location |
|
|
Create index with target’s values |
|
|
Alter Index or MultiIndex name |
|
|
Set Index or MultiIndex name |
Missing Data#
Method |
Description |
Example |
|---|---|---|
|
Return Index without NA/NaN values |
|
|
Fill NA/NaN values with the specified value |
|
|
Detect missing values |
|
|
Detect missing values (alias for isna) |
|
|
Detect existing (non-missing) values |
|
|
Detect existing (non-missing) values (alias for notna) |
Statistics#
Method |
Description |
Example |
|---|---|---|
|
Return the maximum value |
|
|
Return the minimum value |
|
|
Return number of unique elements in the object |
|
|
Return a Series containing counts of unique values |
Aggregation#
Method |
Description |
Example |
|---|---|---|
|
Group the index labels by a given array of values |
|
|
Map values using an input mapping or function |
Comparison#
Method |
Description |
Example |
|---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
Determine if two Index objects contain the same elements |
Sorting#
Method |
Description |
Example |
|---|---|---|
|
Return the integer indices that would sort the index |
|
|
Find indices where elements should be inserted to maintain order |
|
|
Return a sorted copy of the index |
Reshaping#
Method |
Description |
Example |
|---|---|---|
|
Create a DataFrame with a column containing the Index |
|
|
Return the transpose, which is itself |
Combining#
Method |
Description |
Example |
|---|---|---|
|
Append a collection of Index options together |
|
|
Compute join between this and another RangeIndex |
Time Series#
Method |
Description |
Example |
|---|---|---|
|
Return the label from the index, or, if not present, the previous one |
|
|
Computes the difference between consecutive values |
|
|
Shift index by desired number of periods |
I/O#
Method |
Description |
Example |
|---|---|---|
|
Identity method - returns itself for non-MultiIndex |
|
|
Return a list of the values |
|
|
A NumPy ndarray representing the values in this Index |
|
|
Create a Series with both index and values equal to the index keys |
|
|
Return a list of the values |
Conversion#
Method |
Description |
Example |
|---|---|---|
|
Create an Index with values cast to dtypes |
|
|
Make a copy of this object |
|
|
Attempt to infer better dtypes for object columns |
|
|
New view of the index |
Iteration#
Method |
Description |
Example |
|---|---|---|
|
||
|
||
|
Set Operations#
Method |
Description |
Example |
|---|---|---|
|
Return a new Index with elements of index not in other |
|
|
Return Index with duplicate values removed |
|
|
Indicate duplicate index values |
|
|
Form the intersection of two Index objects |
|
|
Return a boolean array where the index values are in values |
|
|
Compute the symmetric difference of two Index objects |
|
|
Form the union of two Index objects |
|
|
Return unique values in the index |
Datetime Methods#
Method |
Description |
Example |
|---|---|---|
|
Round each value in the Index to the given number of decimals |
Other Methods#
Method |
Description |
Example |
|---|---|---|
|
||
|
||
|
Return str(self). |
|
|
Return whether all elements are Truthy |
|
|
Return whether any element is Truthy |
|
|
Return int position of the largest value in the Series |
|
|
Return int position of the smallest value in the Series |
|
|
Return the locations (indices) of labels in the index |
|
|
Make new Index with passed location(-s) deleted |
|
|
Encode the object as an enumerated type or categorical variable |
|
|
Render a string representation of the Index |
|
|
Compute indexer and mask for new index given current index |
|
|
Get indexer for target elements |
|
|
Compute indexer and mask for new index given current index |
|
|
Return an Index of values for requested level |
|
|
Get integer location for requested label |
|
|
Calculate slice bound that corresponds to given label |
|
|
Whether the index holds integer dtypes |
|
|
Similar to equals, but also checks that names and dtypes are equal |
|
|
Return the first element of the underlying data as a Python scalar |
|
|
Memory usage of the values |
|
|
Return a new Index of the values set with the mask |
|
|
Return a flattened array |
|
|
Repeat elements of a Index |
|
|
Compute slice indexer for input labels and step |
|
|
Compute slice locations for input labels |
|
|
DEPRECATED: use sort_values instead |
|
|
For internal compatibility with MultiIndex |
Code Examples#
The following examples are extracted from the test suite.
str (test_interval_multi_range_str.py:209)
199def test_rangeindex_str_call_with_data():
200 """Test RangeIndex.str(data) call."""
201 print("Testing RangeIndex.str(data) call...")
202
203 # Create a RangeIndex
204 ri = pandasCore.RangeIndex(3)
205
206 # Call RangeIndex.str with the index as argument
207 try:
208 str_accessor = pandasCore.RangeIndex.str(ri)
209 print(f" RangeIndex.str(ri) returned: {type(str_accessor)}")
210 print(" PASSED: RangeIndex.str(data) call works")
211 except Exception as e:
212 # Expected to raise error since RangeIndex doesn't contain strings
213 print(f" Error (expected for non-string data): {e}")
214 print(" PASSED: Appropriate error raised for non-string Index")
215
216# =============================================================================
217# Main test function
218# =============================================================================
__init__ (test_example.py:222)
212 f_print_error(f"Exception: {e}")
213 return False
214
215
216def test_range_index():
217 """Test RangeIndex creation"""
218 f_print_header("Test: RangeIndex Creation")
219
220 try:
221 # Create RangeIndex
222 idx = pandasCore.RangeIndex(0, 10, 2)
223 f_print_success("Created RangeIndex(0, 10, 2)")
224
225 # Check properties
226 if idx.start == 0:
227 f_print_success(f"start is correct: {idx.start}")
228 else:
229 f_print_error(f"start is wrong: {idx.start}, expected 0")
230 return False
231
232 if idx.stop == 10: