Create index with target's values. Parameters ---------- target : an iterable An iterable containing the values to be used for creating the new index. method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional * default:
(
self,
target,
method: ReindexMethod | None = None,
level=None,
limit: int | None = None,
tolerance: float | None = None,
)
| 4145 | raise ValueError("cannot reindex on an axis with duplicate labels") |
| 4146 | |
| 4147 | def reindex( |
| 4148 | self, |
| 4149 | target, |
| 4150 | method: ReindexMethod | None = None, |
| 4151 | level=None, |
| 4152 | limit: int | None = None, |
| 4153 | tolerance: float | None = None, |
| 4154 | ) -> tuple[Index, npt.NDArray[np.intp] | None]: |
| 4155 | """ |
| 4156 | Create index with target's values. |
| 4157 | |
| 4158 | Parameters |
| 4159 | ---------- |
| 4160 | target : an iterable |
| 4161 | An iterable containing the values to be used for creating the new index. |
| 4162 | method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional |
| 4163 | * default: exact matches only. |
| 4164 | * pad / ffill: find the PREVIOUS index value if no exact match. |
| 4165 | * backfill / bfill: use NEXT index value if no exact match |
| 4166 | * nearest: use the NEAREST index value if no exact match. Tied |
| 4167 | distances are broken by preferring the larger index value. |
| 4168 | level : int, optional |
| 4169 | Level of multiindex. |
| 4170 | limit : int, optional |
| 4171 | Maximum number of consecutive labels in ``target`` to match for |
| 4172 | inexact matches. |
| 4173 | tolerance : int, float, or list-like, optional |
| 4174 | Maximum distance between original and new labels for inexact |
| 4175 | matches. The values of the index at the matching locations must |
| 4176 | satisfy the equation ``abs(index[indexer] - target) <= tolerance``. |
| 4177 | |
| 4178 | Tolerance may be a scalar value, which applies the same tolerance |
| 4179 | to all values, or list-like, which applies variable tolerance per |
| 4180 | element. List-like includes list, tuple, array, Series, and must be |
| 4181 | the same size as the index and its dtype must exactly match the |
| 4182 | index's type. |
| 4183 | |
| 4184 | Returns |
| 4185 | ------- |
| 4186 | new_index : pd.Index |
| 4187 | Resulting index. |
| 4188 | indexer : np.ndarray[np.intp] or None |
| 4189 | Indices of output values in original index. |
| 4190 | |
| 4191 | Raises |
| 4192 | ------ |
| 4193 | TypeError |
| 4194 | If ``method`` passed along with ``level``. |
| 4195 | ValueError |
| 4196 | If non-unique multi-index |
| 4197 | ValueError |
| 4198 | If non-unique index and ``method`` or ``limit`` passed. |
| 4199 | |
| 4200 | See Also |
| 4201 | -------- |
| 4202 | Series.reindex : Conform Series to new index with optional filling logic. |
| 4203 | DataFrame.reindex : Conform DataFrame to new index with optional filling logic. |
| 4204 |