Return a new MultiIndex of the values selected by the indices. For internal compatibility with numpy arrays. Parameters ---------- indices : array-like Indices to be taken. axis : {0 or 'index'}, optional The axis over which
(
self: MultiIndex,
indices,
axis: Axis = 0,
allow_fill: bool = True,
fill_value=None,
**kwargs,
)
| 2476 | ) |
| 2477 | |
| 2478 | def take( |
| 2479 | self: MultiIndex, |
| 2480 | indices, |
| 2481 | axis: Axis = 0, |
| 2482 | allow_fill: bool = True, |
| 2483 | fill_value=None, |
| 2484 | **kwargs, |
| 2485 | ) -> MultiIndex: |
| 2486 | """ |
| 2487 | Return a new MultiIndex of the values selected by the indices. |
| 2488 | |
| 2489 | For internal compatibility with numpy arrays. |
| 2490 | |
| 2491 | Parameters |
| 2492 | ---------- |
| 2493 | indices : array-like |
| 2494 | Indices to be taken. |
| 2495 | axis : {0 or 'index'}, optional |
| 2496 | The axis over which to select values, always 0 or 'index'. |
| 2497 | allow_fill : bool, default True |
| 2498 | How to handle negative values in `indices`. |
| 2499 | |
| 2500 | * False: negative values in `indices` indicate positional indices |
| 2501 | from the right (the default). This is similar to |
| 2502 | :func:`numpy.take`. |
| 2503 | |
| 2504 | * True: negative values in `indices` indicate |
| 2505 | missing values. These values are set to `fill_value`. Any other |
| 2506 | other negative values raise a ``ValueError``. |
| 2507 | |
| 2508 | fill_value : scalar, default None |
| 2509 | If allow_fill=True and fill_value is not None, indices specified by |
| 2510 | -1 are regarded as NA. If Index doesn't hold NA, raise ValueError. |
| 2511 | **kwargs |
| 2512 | Required for compatibility with numpy. |
| 2513 | |
| 2514 | Returns |
| 2515 | ------- |
| 2516 | Index |
| 2517 | An index formed of elements at the given indices. Will be the same |
| 2518 | type as self, except for RangeIndex. |
| 2519 | |
| 2520 | See Also |
| 2521 | -------- |
| 2522 | numpy.ndarray.take: Return an array formed from the |
| 2523 | elements of a at the given indices. |
| 2524 | |
| 2525 | Examples |
| 2526 | -------- |
| 2527 | >>> idx = pd.MultiIndex.from_arrays([["a", "b", "c"], [1, 2, 3]]) |
| 2528 | >>> idx |
| 2529 | MultiIndex([('a', 1), |
| 2530 | ('b', 2), |
| 2531 | ('c', 3)], |
| 2532 | ) |
| 2533 | >>> idx.take([2, 2, 1, 0]) |
| 2534 | MultiIndex([('c', 3), |
| 2535 | ('c', 3), |
no test coverage detected