Return a new Index 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 to se
(
self,
indices,
axis: Axis = 0,
allow_fill: bool = True,
fill_value=None,
**kwargs,
)
| 1226 | """ |
| 1227 | |
| 1228 | def take( |
| 1229 | self, |
| 1230 | indices, |
| 1231 | axis: Axis = 0, |
| 1232 | allow_fill: bool = True, |
| 1233 | fill_value=None, |
| 1234 | **kwargs, |
| 1235 | ) -> Self: |
| 1236 | """ |
| 1237 | Return a new Index of the values selected by the indices. |
| 1238 | |
| 1239 | For internal compatibility with numpy arrays. |
| 1240 | |
| 1241 | Parameters |
| 1242 | ---------- |
| 1243 | indices : array-like |
| 1244 | Indices to be taken. |
| 1245 | axis : {0 or 'index'}, optional |
| 1246 | The axis over which to select values, always 0 or 'index'. |
| 1247 | allow_fill : bool, default True |
| 1248 | How to handle negative values in `indices`. |
| 1249 | |
| 1250 | * False: negative values in `indices` indicate positional indices |
| 1251 | from the right (the default). This is similar to |
| 1252 | :func:`numpy.take`. |
| 1253 | |
| 1254 | * True: negative values in `indices` indicate |
| 1255 | missing values. These values are set to `fill_value`. Any |
| 1256 | other negative values raise a ``ValueError``. |
| 1257 | |
| 1258 | fill_value : scalar, default None |
| 1259 | If allow_fill=True and fill_value is not None, indices specified by |
| 1260 | -1 are regarded as NA. If Index doesn't hold NA, raise ValueError. |
| 1261 | **kwargs |
| 1262 | Required for compatibility with numpy. |
| 1263 | |
| 1264 | Returns |
| 1265 | ------- |
| 1266 | Index |
| 1267 | An index formed of elements at the given indices. Will be the same |
| 1268 | type as self, except for RangeIndex. |
| 1269 | |
| 1270 | See Also |
| 1271 | -------- |
| 1272 | numpy.ndarray.take: Return an array formed from the |
| 1273 | elements of a at the given indices. |
| 1274 | |
| 1275 | Examples |
| 1276 | -------- |
| 1277 | >>> idx = pd.Index(["a", "b", "c"]) |
| 1278 | >>> idx.take([2, 2, 1, 2]) |
| 1279 | Index(['c', 'c', 'b', 'c'], dtype='str') |
| 1280 | """ |
| 1281 | if kwargs: |
| 1282 | nv.validate_take((), kwargs) |
| 1283 | if is_scalar(indices): |
| 1284 | raise TypeError("Expected indices to be array-like") |
| 1285 | indices = ensure_platform_int(indices) |