@@ -803,6 +803,15 @@ def is_(self, other) -> bool:
803
803
See Also
804
804
--------
805
805
Index.identical : Works like ``Index.is_`` but also checks metadata.
806
+
807
+ Examples
808
+ --------
809
+ >>> idx1 = pd.Index(['1', '2', '3'])
810
+ >>> idx1.is_(idx1.view())
811
+ True
812
+
813
+ >>> idx1.is_(idx1.copy())
814
+ False
806
815
"""
807
816
if self is other :
808
817
return True
@@ -1109,6 +1118,12 @@ def astype(self, dtype, copy: bool = True):
1109
1118
--------
1110
1119
numpy.ndarray.take: Return an array formed from the
1111
1120
elements of a at the given indices.
1121
+
1122
+ Examples
1123
+ --------
1124
+ >>> idx = pd.Index(['a', 'b', 'c'])
1125
+ >>> idx.take([2, 2, 1, 2])
1126
+ Index(['c', 'c', 'b', 'c'], dtype='object')
1112
1127
"""
1113
1128
1114
1129
@Appender (_index_shared_docs ["take" ] % _index_doc_kwargs )
@@ -2986,6 +3001,12 @@ def unique(self, level: Hashable | None = None) -> Self:
2986
3001
--------
2987
3002
unique : Numpy array of unique values in that column.
2988
3003
Series.unique : Return unique values of Series object.
3004
+
3005
+ Examples
3006
+ --------
3007
+ >>> idx = pd.Index([1, 1, 2, 3, 3])
3008
+ >>> idx.unique()
3009
+ Index([1, 2, 3], dtype='int64')
2989
3010
"""
2990
3011
if level is not None :
2991
3012
self ._validate_index_level (level )
@@ -5379,6 +5400,13 @@ def putmask(self, mask, value) -> Index:
5379
5400
--------
5380
5401
numpy.ndarray.putmask : Changes elements of an array
5381
5402
based on conditional and input values.
5403
+
5404
+ Examples
5405
+ --------
5406
+ >>> idx1 = pd.Index([1, 2, 3])
5407
+ >>> idx2 = pd.Index([5, 6, 7])
5408
+ >>> idx1.putmask([True, False, False], idx2)
5409
+ Index([5, 2, 3], dtype='int64')
5382
5410
"""
5383
5411
mask , noop = validate_putmask (self ._values , mask )
5384
5412
if noop :
@@ -5508,6 +5536,18 @@ def identical(self, other) -> bool:
5508
5536
bool
5509
5537
If two Index objects have equal elements and same type True,
5510
5538
otherwise False.
5539
+
5540
+ Examples
5541
+ --------
5542
+ >>> idx1 = pd.Index(['1', '2', '3'])
5543
+ >>> idx2 = pd.Index(['1', '2', '3'])
5544
+ >>> idx2.identical(idx1)
5545
+ True
5546
+
5547
+ >>> idx1 = pd.Index(['1', '2', '3'], name="A")
5548
+ >>> idx2 = pd.Index(['1', '2', '3'], name="B")
5549
+ >>> idx2.identical(idx1)
5550
+ False
5511
5551
"""
5512
5552
return (
5513
5553
self .equals (other )
@@ -6728,6 +6768,12 @@ def insert(self, loc: int, item) -> Index:
6728
6768
Returns
6729
6769
-------
6730
6770
Index
6771
+
6772
+ Examples
6773
+ --------
6774
+ >>> idx = pd.Index(['a', 'b', 'c'])
6775
+ >>> idx.insert(1, 'x')
6776
+ Index(['a', 'x', 'b', 'c'], dtype='object')
6731
6777
"""
6732
6778
item = lib .item_from_zerodim (item )
6733
6779
if is_valid_na_for_dtype (item , self .dtype ) and self .dtype != object :
@@ -6789,6 +6835,12 @@ def drop(
6789
6835
------
6790
6836
KeyError
6791
6837
If not all of the labels are found in the selected axis
6838
+
6839
+ Examples
6840
+ --------
6841
+ >>> idx = pd.Index(['a', 'b', 'c'])
6842
+ >>> idx.drop(['a'])
6843
+ Index(['b', 'c'], dtype='object')
6792
6844
"""
6793
6845
if not isinstance (labels , Index ):
6794
6846
# avoid materializing e.g. RangeIndex
0 commit comments