RangeIndex ========== .. currentmodule:: pandasCore .. class:: RangeIndex Immutable Index implementing a monotonic integer range. Example ------- .. code-block:: python import pandasCore as pd # Create RangeIndex idx = pd.RangeIndex([1, 2, 3], name='my_index') print(len(idx)) # 3 Attributes ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Attribute - Description - Example * - :attr:`~RangeIndex.dtype` - Return the dtype object of the underlying data - * - :attr:`~RangeIndex.empty` - Whether the Index is empty - * - :attr:`~RangeIndex.has_duplicates` - Return if the Index has duplicate values - * - :attr:`~RangeIndex.is_monotonic_decreasing` - Return boolean if values in the object are monotonically decreasing - * - :attr:`~RangeIndex.is_monotonic_increasing` - Return boolean if values in the object are monotonically increasing - * - :attr:`~RangeIndex.is_unique` - Return if the Index has unique values - * - :attr:`~RangeIndex.name` - Return Index or MultiIndex name - * - :attr:`~RangeIndex.nbytes` - Return the number of bytes in the underlying data - * - :attr:`~RangeIndex.ndim` - Number of dimensions of the underlying data, by definition 1 - * - :attr:`~RangeIndex.nlevels` - Number of levels - * - :attr:`~RangeIndex.shape` - Return a tuple of the shape of the underlying data - * - :attr:`~RangeIndex.size` - Return the number of elements - * - :attr:`~RangeIndex.start` - The value of the start parameter - * - :attr:`~RangeIndex.step` - The value of the step parameter - * - :attr:`~RangeIndex.stop` - The value of the stop parameter - * - :attr:`~RangeIndex.str` - Vectorized string functions for Index. - :ref:`View ` Construction ------------ .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.__init__` ``(*args, **kwargs) | () | (start: object = None, stop: object = None, step: object = None, dtype: object = None, copy: bool = False, name: str | None = None)`` - Create an empty RangeIndex - :ref:`View ` Indexing / Selection -------------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.__getitem__` ``(arg0: object)`` - - * - :meth:`~RangeIndex.take` ``(indices: object, axis: typing.SupportsInt = 0, allow_fill: bool = True, fill_value: object = None, **kwargs)`` - Return a new Index of the values selected by the indices - * - :meth:`~RangeIndex.where` ``(cond: object, other: object = None)`` - Replace values where the condition is False - Data Manipulation ----------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.drop` ``(labels: object, errors: str = 'raise')`` - Make new Index with passed list of labels deleted - * - :meth:`~RangeIndex.droplevel` ``(level: object = 0)`` - Return index with requested level(s) removed - * - :meth:`~RangeIndex.insert` ``(loc: typing.SupportsInt, item: typing.SupportsInt)`` - Make new Index inserting new item at location - * - :meth:`~RangeIndex.reindex` ``(target: object, method: object = None, level: object = None, limit: object = None, tolerance: object = None)`` - Create index with target's values - * - :meth:`~RangeIndex.rename` ``(name: object, *, inplace: bool = False)`` - Alter Index or MultiIndex name - * - :meth:`~RangeIndex.set_names` ``(names: object, *, level: object = None, inplace: bool = False)`` - Set Index or MultiIndex name - Missing Data ------------ .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.dropna` ``(how: str = 'any')`` - Return Index without NA/NaN values - * - :meth:`~RangeIndex.fillna` ``(value: object = None, downcast: object = None)`` - Fill NA/NaN values with the specified value - * - :meth:`~RangeIndex.isna` ``()`` - Detect missing values - * - :meth:`~RangeIndex.isnull` ``()`` - Detect missing values (alias for isna) - * - :meth:`~RangeIndex.notna` ``()`` - Detect existing (non-missing) values - * - :meth:`~RangeIndex.notnull` ``()`` - Detect existing (non-missing) values (alias for notna) - Statistics ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.max` ``(axis: object = None, skipna: bool = True, *args, **kwargs)`` - Return the maximum value - * - :meth:`~RangeIndex.min` ``(axis: object = None, skipna: bool = True, *args, **kwargs)`` - Return the minimum value - * - :meth:`~RangeIndex.nunique` ``(dropna: bool = True)`` - Return number of unique elements in the object - * - :meth:`~RangeIndex.value_counts` ``(normalize: bool = False, sort: bool = True, ascending: bool = False, bins: object = None, dropna: bool = True)`` - Return a Series containing counts of unique values - Aggregation ----------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.groupby` ``(values: object)`` - Group the index labels by a given array of values - * - :meth:`~RangeIndex.map` ``(mapper: object, na_action: object = None)`` - Map values using an input mapping or function - Comparison ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.__eq__` ``(arg0: object)`` - - * - :meth:`~RangeIndex.__ge__` ``(arg0: typing.SupportsInt)`` - - * - :meth:`~RangeIndex.__gt__` ``(arg0: typing.SupportsInt)`` - - * - :meth:`~RangeIndex.__le__` ``(arg0: typing.SupportsInt)`` - - * - :meth:`~RangeIndex.__lt__` ``(arg0: typing.SupportsInt)`` - - * - :meth:`~RangeIndex.__ne__` ``(arg0: object)`` - - * - :meth:`~RangeIndex.equals` ``(other: object)`` - Determine if two Index objects contain the same elements - Sorting ------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.argsort` ``(*args, **kwargs)`` - Return the integer indices that would sort the index - * - :meth:`~RangeIndex.searchsorted` ``(value: object, side: str = 'left', sorter: object = None)`` - Find indices where elements should be inserted to maintain order - * - :meth:`~RangeIndex.sort_values` ``(*, return_indexer: bool = False, ascending: bool = True, na_position: str = 'last', key: object = None)`` - Return a sorted copy of the index - Reshaping --------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.to_frame` ``(index: bool = True, name: object = None)`` - Create a DataFrame with a column containing the Index - * - :meth:`~RangeIndex.transpose` ``(*args, **kwargs)`` - Return the transpose, which is itself - Combining --------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.append` ``(other: object)`` - Append a collection of Index options together - * - :meth:`~RangeIndex.join` ``(other: pandasCore.RangeIndex, *, how: str = 'left', level: object = None, return_indexers: bool = False, sort: bool = False)`` - Compute join between this and another RangeIndex - Time Series ----------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.asof` ``(label: typing.SupportsInt)`` - Return the label from the index, or, if not present, the previous one - * - :meth:`~RangeIndex.diff` ``(periods: typing.SupportsInt = 1)`` - Computes the difference between consecutive values - * - :meth:`~RangeIndex.shift` ``(periods: typing.SupportsInt = 1, freq: object = None)`` - Shift index by desired number of periods - I/O --- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.to_flat_index` ``()`` - Identity method - returns itself for non-MultiIndex - * - :meth:`~RangeIndex.to_list` ``()`` - Return a list of the values - * - :meth:`~RangeIndex.to_numpy` ``(dtype: object = None, copy: bool = False, na_value: object = None, **kwargs)`` - A NumPy ndarray representing the values in this Index - * - :meth:`~RangeIndex.to_series` ``(index: object = None, name: object = None)`` - Create a Series with both index and values equal to the index keys - * - :meth:`~RangeIndex.tolist` ``()`` - Return a list of the values - Conversion ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.astype` ``(dtype: object, copy: bool = True)`` - Create an Index with values cast to dtypes - * - :meth:`~RangeIndex.copy` ``(name: object = None, deep: bool = False)`` - Make a copy of this object - * - :meth:`~RangeIndex.infer_objects` ``(copy: bool = True)`` - Attempt to infer better dtypes for object columns - * - :meth:`~RangeIndex.view` ``(cls: object = None)`` - New view of the index - Iteration --------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.__contains__` ``(arg0: typing.SupportsInt)`` - - * - :meth:`~RangeIndex.__iter__` ``()`` - - * - :meth:`~RangeIndex.__len__` ``()`` - - Set Operations -------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.difference` ``(other: object, sort: object = None)`` - Return a new Index with elements of index not in other - * - :meth:`~RangeIndex.drop_duplicates` ``(*, keep: str = 'first')`` - Return Index with duplicate values removed - * - :meth:`~RangeIndex.duplicated` ``(keep: str = 'first')`` - Indicate duplicate index values - * - :meth:`~RangeIndex.intersection` ``(other: object, sort: bool = False)`` - Form the intersection of two Index objects - * - :meth:`~RangeIndex.isin` ``(values: object, level: object = None)`` - Return a boolean array where the index values are in values - * - :meth:`~RangeIndex.symmetric_difference` ``(other: object, result_name: object = None, sort: object = None)`` - Compute the symmetric difference of two Index objects - * - :meth:`~RangeIndex.union` ``(other: object, sort: object = None)`` - Form the union of two Index objects - * - :meth:`~RangeIndex.unique` ``(level: object = None)`` - Return unique values in the index - Datetime Methods ---------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.round` ``(decimals: typing.SupportsInt = 0)`` - Round each value in the Index to the given number of decimals - Other Methods ------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~RangeIndex.__hash__` - - * - :meth:`~RangeIndex.__repr__` ``()`` - - * - :meth:`~RangeIndex.__str__` ``(self, /)`` - Return str(self). - * - :meth:`~RangeIndex.all` ``(*args, **kwargs)`` - Return whether all elements are Truthy - * - :meth:`~RangeIndex.any` ``(*args, **kwargs)`` - Return whether any element is Truthy - * - :meth:`~RangeIndex.argmax` ``(axis: object = None, skipna: bool = True, *args, **kwargs)`` - Return int position of the largest value in the Series - * - :meth:`~RangeIndex.argmin` ``(axis: object = None, skipna: bool = True, *args, **kwargs)`` - Return int position of the smallest value in the Series - * - :meth:`~RangeIndex.asof_locs` ``(where: object, mask: object = None)`` - Return the locations (indices) of labels in the index - * - :meth:`~RangeIndex.delete` ``(loc: object)`` - Make new Index with passed location(-s) deleted - * - :meth:`~RangeIndex.factorize` ``(sort: bool = False, use_na_sentinel: bool = True)`` - Encode the object as an enumerated type or categorical variable - * - :meth:`~RangeIndex.format` ``(name: bool = False, formatter: object = None, na_rep: str = 'NaN')`` - Render a string representation of the Index - * - :meth:`~RangeIndex.get_indexer` ``(target: object, method: object = None, limit: object = None, tolerance: object = None)`` - Compute indexer and mask for new index given current index - * - :meth:`~RangeIndex.get_indexer_for` ``(target: object)`` - Get indexer for target elements - * - :meth:`~RangeIndex.get_indexer_non_unique` ``(target: object)`` - Compute indexer and mask for new index given current index - * - :meth:`~RangeIndex.get_level_values` ``(level: object)`` - Return an Index of values for requested level - * - :meth:`~RangeIndex.get_loc` ``(key: typing.SupportsInt)`` - Get integer location for requested label - * - :meth:`~RangeIndex.get_slice_bound` ``(label: typing.SupportsInt, side: str)`` - Calculate slice bound that corresponds to given label - * - :meth:`~RangeIndex.holds_integer` ``()`` - Whether the index holds integer dtypes - * - :meth:`~RangeIndex.identical` ``(other: object)`` - Similar to equals, but also checks that names and dtypes are equal - * - :meth:`~RangeIndex.item` ``()`` - Return the first element of the underlying data as a Python scalar - * - :meth:`~RangeIndex.memory_usage` ``(deep: bool = False)`` - Memory usage of the values - * - :meth:`~RangeIndex.putmask` ``(mask: object, value: object)`` - Return a new Index of the values set with the mask - * - :meth:`~RangeIndex.ravel` ``(order: str = 'C')`` - Return a flattened array - * - :meth:`~RangeIndex.repeat` ``(repeats: object, axis: object = None)`` - Repeat elements of a Index - * - :meth:`~RangeIndex.slice_indexer` ``(start: object = None, end: object = None, step: object = None)`` - Compute slice indexer for input labels and step - * - :meth:`~RangeIndex.slice_locs` ``(start: object = None, end: object = None, step: object = None)`` - Compute slice locations for input labels - * - :meth:`~RangeIndex.sort` ``(*args, **kwargs)`` - DEPRECATED: use sort_values instead - * - :meth:`~RangeIndex.sortlevel` ``(level: object = None, ascending: bool = True, sort_remaining: object = None, na_position: str = 'first')`` - For internal compatibility with MultiIndex - Code Examples ------------- The following examples are extracted from the test suite. .. _example-rangeindex-str-0: .. dropdown:: str (test_interval_multi_range_str.py:209) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 199 :emphasize-lines: 11 def test_rangeindex_str_call_with_data(): """Test RangeIndex.str(data) call.""" print("Testing RangeIndex.str(data) call...") # Create a RangeIndex ri = pandasCore.RangeIndex(3) # Call RangeIndex.str with the index as argument try: str_accessor = pandasCore.RangeIndex.str(ri) print(f" RangeIndex.str(ri) returned: {type(str_accessor)}") print(" PASSED: RangeIndex.str(data) call works") except Exception as e: # Expected to raise error since RangeIndex doesn't contain strings print(f" Error (expected for non-string data): {e}") print(" PASSED: Appropriate error raised for non-string Index") # ============================================================================= # Main test function # ============================================================================= .. _example-rangeindex-dunder-initdunder--1: .. dropdown:: __init__ (test_example.py:222) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 212 :emphasize-lines: 11 f_print_error(f"Exception: {e}") return False def test_range_index(): """Test RangeIndex creation""" f_print_header("Test: RangeIndex Creation") try: # Create RangeIndex idx = pandasCore.RangeIndex(0, 10, 2) f_print_success("Created RangeIndex(0, 10, 2)") # Check properties if idx.start == 0: f_print_success(f"start is correct: {idx.start}") else: f_print_error(f"start is wrong: {idx.start}, expected 0") return False if idx.stop == 10: