@@ -799,6 +799,18 @@ def is_(self, other) -> bool:
799
799
See Also
800
800
--------
801
801
Index.identical : Works like ``Index.is_`` but also checks metadata.
802
+
803
+ Examples
804
+ --------
805
+ >>> idx1 = pd.Index(['1', '2', '3'])
806
+ >>> idx2 = pd.Index(['1', '2', '3'])
807
+ >>> idx2.is_(idx1)
808
+ False
809
+
810
+ >>> idx1 = pd.Index(['1', '2', '3'])
811
+ >>> new_name = idx1
812
+ >>> new_name.is_(idx1)
813
+ True
802
814
"""
803
815
if self is other :
804
816
return True
@@ -1089,6 +1101,12 @@ def astype(self, dtype, copy: bool = True):
1089
1101
--------
1090
1102
numpy.ndarray.take: Return an array formed from the
1091
1103
elements of a at the given indices.
1104
+
1105
+ Examples
1106
+ --------
1107
+ >>> idx = pd.Index(['a', 'b', 'c'])
1108
+ >>> idx.take([2])
1109
+ Index(['c'], dtype='object')
1092
1110
"""
1093
1111
1094
1112
@Appender (_index_shared_docs ["take" ] % _index_doc_kwargs )
@@ -1221,6 +1239,13 @@ def copy(
1221
1239
-----
1222
1240
In most cases, there should be no functional difference from using
1223
1241
``deep``, but if ``deep`` is passed it will attempt to deepcopy.
1242
+
1243
+ Examples
1244
+ --------
1245
+ >>> idx = pd.Index(['a', 'b', 'c'])
1246
+ >>> new_idx = idx.copy()
1247
+ >>> idx is new_idx
1248
+ False
1224
1249
"""
1225
1250
1226
1251
name = self ._validate_names (name = name , deep = deep )[0 ]
@@ -2959,6 +2984,12 @@ def unique(self, level: Hashable | None = None) -> Self:
2959
2984
--------
2960
2985
unique : Numpy array of unique values in that column.
2961
2986
Series.unique : Return unique values of Series object.
2987
+
2988
+ Examples
2989
+ --------
2990
+ >>> idx = pd.Index([1, 1, 2, 3, 3])
2991
+ >>> idx.unique()
2992
+ Index([1, 2, 3], dtype='int64')
2962
2993
"""
2963
2994
if level is not None :
2964
2995
self ._validate_index_level (level )
@@ -5338,6 +5369,13 @@ def putmask(self, mask, value) -> Index:
5338
5369
--------
5339
5370
numpy.ndarray.putmask : Changes elements of an array
5340
5371
based on conditional and input values.
5372
+
5373
+ Examples
5374
+ --------
5375
+ >>> idx1 = pd.Index([1, 2, 3])
5376
+ >>> idx2 = pd.Index([5, 6, 7])
5377
+ >>> idx1.putmask([True, False, False], idx2)
5378
+ Index([5, 2, 3], dtype='int64')
5341
5379
"""
5342
5380
mask , noop = validate_putmask (self ._values , mask )
5343
5381
if noop :
@@ -5467,6 +5505,18 @@ def identical(self, other) -> bool:
5467
5505
bool
5468
5506
If two Index objects have equal elements and same type True,
5469
5507
otherwise False.
5508
+
5509
+ Examples
5510
+ --------
5511
+ >>> idx1 = pd.Index(['1', '2', '3'])
5512
+ >>> idx2 = pd.Index(['1', '2', '3'])
5513
+ >>> idx2.identical(idx1)
5514
+ True
5515
+
5516
+ >>> idx1 = pd.Index(['1', '2', '3'], name="A")
5517
+ >>> idx2 = pd.Index(['1', '2', '3'], name="B")
5518
+ >>> idx2.identical(idx1)
5519
+ False
5470
5520
"""
5471
5521
return (
5472
5522
self .equals (other )
@@ -6687,6 +6737,12 @@ def insert(self, loc: int, item) -> Index:
6687
6737
Returns
6688
6738
-------
6689
6739
Index
6740
+
6741
+ Examples
6742
+ --------
6743
+ >>> idx = pd.Index(['a', 'b', 'c'])
6744
+ >>> idx.insert(1, 'x')
6745
+ Index(['a', 'x', 'b', 'c'], dtype='object')
6690
6746
"""
6691
6747
item = lib .item_from_zerodim (item )
6692
6748
if is_valid_na_for_dtype (item , self .dtype ) and self .dtype != object :
@@ -6748,6 +6804,12 @@ def drop(
6748
6804
------
6749
6805
KeyError
6750
6806
If not all of the labels are found in the selected axis
6807
+
6808
+ Examples
6809
+ --------
6810
+ >>> idx = pd.Index(['a', 'b', 'c'])
6811
+ >>> idx.drop(['a'])
6812
+ Index(['b', 'c'], dtype='object')
6751
6813
"""
6752
6814
if not isinstance (labels , Index ):
6753
6815
# avoid materializing e.g. RangeIndex
0 commit comments