@@ -1056,6 +1056,14 @@ def astype(self, dtype, copy: bool = True):
1056
1056
-------
1057
1057
Index
1058
1058
Index with values cast to specified dtype.
1059
+
1060
+ Examples
1061
+ --------
1062
+ >>> idx = pd.Index([1, 2, 3])
1063
+ >>> idx
1064
+ Index([1, 2, 3], dtype='int64')
1065
+ >>> idx.astype('float')
1066
+ Index([1.0, 2.0, 3.0], dtype='float64')
1059
1067
"""
1060
1068
if dtype is not None :
1061
1069
dtype = pandas_dtype (dtype )
@@ -2939,6 +2947,12 @@ def fillna(self, value=None, downcast=None):
2939
2947
--------
2940
2948
DataFrame.fillna : Fill NaN values of a DataFrame.
2941
2949
Series.fillna : Fill NaN Values of a Series.
2950
+
2951
+ Examples
2952
+ --------
2953
+ >>> idx = pd.Index([np.nan, np.nan, 3])
2954
+ >>> idx.fillna(0)
2955
+ Index([0.0, 0.0, 3.0], dtype='float64')
2942
2956
"""
2943
2957
if not is_scalar (value ):
2944
2958
raise TypeError (f"'value' must be a scalar, passed: { type (value ).__name__ } " )
@@ -2969,6 +2983,12 @@ def dropna(self, how: AnyAll = "any") -> Self:
2969
2983
Returns
2970
2984
-------
2971
2985
Index
2986
+
2987
+ Examples
2988
+ --------
2989
+ >>> idx = pd.Index([1, np.nan, 3])
2990
+ >>> idx.dropna()
2991
+ Index([1.0, 3.0], dtype='float64')
2972
2992
"""
2973
2993
if how not in ("any" , "all" ):
2974
2994
raise ValueError (f"invalid how option: { how } " )
@@ -4535,6 +4555,13 @@ def join(
4535
4555
Returns
4536
4556
-------
4537
4557
join_index, (left_indexer, right_indexer)
4558
+
4559
+ Examples
4560
+ --------
4561
+ >>> idx1 = pd.Index([1, 2, 3])
4562
+ >>> idx2 = pd.Index([4, 5, 6])
4563
+ >>> idx1.join(idx2, how='outer')
4564
+ Index([1, 2, 3, 4, 5, 6], dtype='int64')
4538
4565
"""
4539
4566
other = ensure_index (other )
4540
4567
@@ -5359,6 +5386,12 @@ def append(self, other: Index | Sequence[Index]) -> Index:
5359
5386
Returns
5360
5387
-------
5361
5388
Index
5389
+
5390
+ Examples
5391
+ --------
5392
+ >>> idx = pd.Index([1, 2, 3])
5393
+ >>> idx.append(pd.Index([4]))
5394
+ Index([1, 2, 3, 4], dtype='int64')
5362
5395
"""
5363
5396
to_concat = [self ]
5364
5397
@@ -6295,6 +6328,22 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
6295
6328
The output of the mapping function applied to the index.
6296
6329
If the function returns a tuple with more than one element
6297
6330
a MultiIndex will be returned.
6331
+
6332
+ Examples
6333
+ --------
6334
+ >>> idx = pd.Index([1, 2, 3])
6335
+ >>> idx.map({1: 'a', 2: 'b', 3: 'c'})
6336
+ Index(['a', 'b', 'c'], dtype='object')
6337
+
6338
+ Using `map` with a function:
6339
+
6340
+ >>> idx = pd.Index([1, 2, 3])
6341
+ >>> idx.map('I am a {}'.format)
6342
+ Index(['I am a 1', 'I am a 2', 'I am a 3'], dtype='object')
6343
+
6344
+ >>> idx = pd.Index(['a', 'b', 'c'])
6345
+ >>> idx.map(lambda x: x.upper())
6346
+ Index(['A', 'B', 'C'], dtype='object')
6298
6347
"""
6299
6348
from pandas .core .indexes .multi import MultiIndex
6300
6349
0 commit comments