@@ -812,6 +812,15 @@ def is_(self, other) -> bool:
812
812
See Also
813
813
--------
814
814
Index.identical : Works like ``Index.is_`` but also checks metadata.
815
+
816
+ Examples
817
+ --------
818
+ >>> idx1 = pd.Index(['1', '2', '3'])
819
+ >>> idx1.is_(idx1.view())
820
+ True
821
+
822
+ >>> idx1.is_(idx1.copy())
823
+ False
815
824
"""
816
825
if self is other :
817
826
return True
@@ -1118,6 +1127,12 @@ def astype(self, dtype, copy: bool = True):
1118
1127
--------
1119
1128
numpy.ndarray.take: Return an array formed from the
1120
1129
elements of a at the given indices.
1130
+
1131
+ Examples
1132
+ --------
1133
+ >>> idx = pd.Index(['a', 'b', 'c'])
1134
+ >>> idx.take([2, 2, 1, 2])
1135
+ Index(['c', 'c', 'b', 'c'], dtype='object')
1121
1136
"""
1122
1137
1123
1138
@Appender (_index_shared_docs ["take" ] % _index_doc_kwargs )
@@ -2995,6 +3010,12 @@ def unique(self, level: Hashable | None = None) -> Self:
2995
3010
--------
2996
3011
unique : Numpy array of unique values in that column.
2997
3012
Series.unique : Return unique values of Series object.
3013
+
3014
+ Examples
3015
+ --------
3016
+ >>> idx = pd.Index([1, 1, 2, 3, 3])
3017
+ >>> idx.unique()
3018
+ Index([1, 2, 3], dtype='int64')
2998
3019
"""
2999
3020
if level is not None :
3000
3021
self ._validate_index_level (level )
@@ -5388,6 +5409,13 @@ def putmask(self, mask, value) -> Index:
5388
5409
--------
5389
5410
numpy.ndarray.putmask : Changes elements of an array
5390
5411
based on conditional and input values.
5412
+
5413
+ Examples
5414
+ --------
5415
+ >>> idx1 = pd.Index([1, 2, 3])
5416
+ >>> idx2 = pd.Index([5, 6, 7])
5417
+ >>> idx1.putmask([True, False, False], idx2)
5418
+ Index([5, 2, 3], dtype='int64')
5391
5419
"""
5392
5420
mask , noop = validate_putmask (self ._values , mask )
5393
5421
if noop :
@@ -5517,6 +5545,18 @@ def identical(self, other) -> bool:
5517
5545
bool
5518
5546
If two Index objects have equal elements and same type True,
5519
5547
otherwise False.
5548
+
5549
+ Examples
5550
+ --------
5551
+ >>> idx1 = pd.Index(['1', '2', '3'])
5552
+ >>> idx2 = pd.Index(['1', '2', '3'])
5553
+ >>> idx2.identical(idx1)
5554
+ True
5555
+
5556
+ >>> idx1 = pd.Index(['1', '2', '3'], name="A")
5557
+ >>> idx2 = pd.Index(['1', '2', '3'], name="B")
5558
+ >>> idx2.identical(idx1)
5559
+ False
5520
5560
"""
5521
5561
return (
5522
5562
self .equals (other )
@@ -6737,6 +6777,12 @@ def insert(self, loc: int, item) -> Index:
6737
6777
Returns
6738
6778
-------
6739
6779
Index
6780
+
6781
+ Examples
6782
+ --------
6783
+ >>> idx = pd.Index(['a', 'b', 'c'])
6784
+ >>> idx.insert(1, 'x')
6785
+ Index(['a', 'x', 'b', 'c'], dtype='object')
6740
6786
"""
6741
6787
item = lib .item_from_zerodim (item )
6742
6788
if is_valid_na_for_dtype (item , self .dtype ) and self .dtype != object :
@@ -6798,6 +6844,12 @@ def drop(
6798
6844
------
6799
6845
KeyError
6800
6846
If not all of the labels are found in the selected axis
6847
+
6848
+ Examples
6849
+ --------
6850
+ >>> idx = pd.Index(['a', 'b', 'c'])
6851
+ >>> idx.drop(['a'])
6852
+ Index(['b', 'c'], dtype='object')
6801
6853
"""
6802
6854
if not isinstance (labels , Index ):
6803
6855
# avoid materializing e.g. RangeIndex
0 commit comments