Make a copy of this object. Name is set on the new object. Parameters ---------- name : Label, optional Set name for new object. deep : bool, default False If True attempts to make a deep copy of the Index. El
(
self,
name: Hashable | None = None,
deep: bool = False,
)
| 1373 | # Copying Methods |
| 1374 | |
| 1375 | def copy( |
| 1376 | self, |
| 1377 | name: Hashable | None = None, |
| 1378 | deep: bool = False, |
| 1379 | ) -> Self: |
| 1380 | """ |
| 1381 | Make a copy of this object. |
| 1382 | |
| 1383 | Name is set on the new object. |
| 1384 | |
| 1385 | Parameters |
| 1386 | ---------- |
| 1387 | name : Label, optional |
| 1388 | Set name for new object. |
| 1389 | deep : bool, default False |
| 1390 | If True attempts to make a deep copy of the Index. |
| 1391 | Else makes a shallow copy. |
| 1392 | |
| 1393 | Returns |
| 1394 | ------- |
| 1395 | Index |
| 1396 | Index refer to new object which is a copy of this object. |
| 1397 | |
| 1398 | See Also |
| 1399 | -------- |
| 1400 | Index.delete: Make new Index with passed location(-s) deleted. |
| 1401 | Index.drop: Make new Index with passed list of labels deleted. |
| 1402 | |
| 1403 | Notes |
| 1404 | ----- |
| 1405 | In most cases, there should be no functional difference from using |
| 1406 | ``deep``, but if ``deep`` is passed it will attempt to deepcopy. |
| 1407 | |
| 1408 | Examples |
| 1409 | -------- |
| 1410 | >>> idx = pd.Index(["a", "b", "c"]) |
| 1411 | >>> new_idx = idx.copy() |
| 1412 | >>> idx is new_idx |
| 1413 | False |
| 1414 | """ |
| 1415 | |
| 1416 | name = self._validate_names(name=name, deep=deep)[0] |
| 1417 | if deep: |
| 1418 | new_data = self._data.copy() |
| 1419 | new_index = type(self)._simple_new(new_data, name=name) |
| 1420 | else: |
| 1421 | new_index = self._rename(name=name) |
| 1422 | return new_index |
| 1423 | |
| 1424 | @final |
| 1425 | def __copy__(self) -> Self: |