@@ -1065,6 +1065,14 @@ def astype(self, dtype, copy: bool = True):
1065
1065
-------
1066
1066
Index
1067
1067
Index with values cast to specified dtype.
1068
+
1069
+ Examples
1070
+ --------
1071
+ >>> idx = pd.Index([1, 2, 3])
1072
+ >>> idx
1073
+ Index([1, 2, 3], dtype='int64')
1074
+ >>> idx.astype('float')
1075
+ Index([1.0, 2.0, 3.0], dtype='float64')
1068
1076
"""
1069
1077
if dtype is not None :
1070
1078
dtype = pandas_dtype (dtype )
@@ -2948,6 +2956,12 @@ def fillna(self, value=None, downcast=None):
2948
2956
--------
2949
2957
DataFrame.fillna : Fill NaN values of a DataFrame.
2950
2958
Series.fillna : Fill NaN Values of a Series.
2959
+
2960
+ Examples
2961
+ --------
2962
+ >>> idx = pd.Index([np.nan, np.nan, 3])
2963
+ >>> idx.fillna(0)
2964
+ Index([0.0, 0.0, 3.0], dtype='float64')
2951
2965
"""
2952
2966
if not is_scalar (value ):
2953
2967
raise TypeError (f"'value' must be a scalar, passed: { type (value ).__name__ } " )
@@ -2978,6 +2992,12 @@ def dropna(self, how: AnyAll = "any") -> Self:
2978
2992
Returns
2979
2993
-------
2980
2994
Index
2995
+
2996
+ Examples
2997
+ --------
2998
+ >>> idx = pd.Index([1, np.nan, 3])
2999
+ >>> idx.dropna()
3000
+ Index([1.0, 3.0], dtype='float64')
2981
3001
"""
2982
3002
if how not in ("any" , "all" ):
2983
3003
raise ValueError (f"invalid how option: { how } " )
@@ -4544,6 +4564,13 @@ def join(
4544
4564
Returns
4545
4565
-------
4546
4566
join_index, (left_indexer, right_indexer)
4567
+
4568
+ Examples
4569
+ --------
4570
+ >>> idx1 = pd.Index([1, 2, 3])
4571
+ >>> idx2 = pd.Index([4, 5, 6])
4572
+ >>> idx1.join(idx2, how='outer')
4573
+ Index([1, 2, 3, 4, 5, 6], dtype='int64')
4547
4574
"""
4548
4575
other = ensure_index (other )
4549
4576
@@ -5368,6 +5395,12 @@ def append(self, other: Index | Sequence[Index]) -> Index:
5368
5395
Returns
5369
5396
-------
5370
5397
Index
5398
+
5399
+ Examples
5400
+ --------
5401
+ >>> idx = pd.Index([1, 2, 3])
5402
+ >>> idx.append(pd.Index([4]))
5403
+ Index([1, 2, 3, 4], dtype='int64')
5371
5404
"""
5372
5405
to_concat = [self ]
5373
5406
@@ -6304,6 +6337,22 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
6304
6337
The output of the mapping function applied to the index.
6305
6338
If the function returns a tuple with more than one element
6306
6339
a MultiIndex will be returned.
6340
+
6341
+ Examples
6342
+ --------
6343
+ >>> idx = pd.Index([1, 2, 3])
6344
+ >>> idx.map({1: 'a', 2: 'b', 3: 'c'})
6345
+ Index(['a', 'b', 'c'], dtype='object')
6346
+
6347
+ Using `map` with a function:
6348
+
6349
+ >>> idx = pd.Index([1, 2, 3])
6350
+ >>> idx.map('I am a {}'.format)
6351
+ Index(['I am a 1', 'I am a 2', 'I am a 3'], dtype='object')
6352
+
6353
+ >>> idx = pd.Index(['a', 'b', 'c'])
6354
+ >>> idx.map(lambda x: x.upper())
6355
+ Index(['A', 'B', 'C'], dtype='object')
6307
6356
"""
6308
6357
from pandas .core .indexes .multi import MultiIndex
6309
6358
0 commit comments