@@ -6155,12 +6155,20 @@ def bfill(
6155
6155
method = "bfill" , axis = axis , inplace = inplace , limit = limit , downcast = downcast
6156
6156
)
6157
6157
6158
- _shared_docs [
6159
- "replace"
6160
- ] = """
6158
+ @doc (klass = _shared_doc_kwargs ["klass" ])
6159
+ def replace (
6160
+ self ,
6161
+ to_replace = None ,
6162
+ value = None ,
6163
+ inplace = False ,
6164
+ limit = None ,
6165
+ regex = False ,
6166
+ method = "pad" ,
6167
+ ):
6168
+ """
6161
6169
Replace values given in `to_replace` with `value`.
6162
6170
6163
- Values of the %( klass)s are replaced with other values dynamically.
6171
+ Values of the { klass} are replaced with other values dynamically.
6164
6172
This differs from updating with ``.loc`` or ``.iloc``, which require
6165
6173
you to specify a location to update with some value.
6166
6174
@@ -6192,19 +6200,19 @@ def bfill(
6192
6200
6193
6201
- Dicts can be used to specify different replacement values
6194
6202
for different existing values. For example,
6195
- ``{'a': 'b', 'y': 'z'}`` replaces the value 'a' with 'b' and
6203
+ ``{{ 'a': 'b', 'y': 'z'} }`` replaces the value 'a' with 'b' and
6196
6204
'y' with 'z'. To use a dict in this way the `value`
6197
6205
parameter should be `None`.
6198
6206
- For a DataFrame a dict can specify that different values
6199
6207
should be replaced in different columns. For example,
6200
- ``{'a': 1, 'b': 'z'}`` looks for the value 1 in column 'a'
6208
+ ``{{ 'a': 1, 'b': 'z'} }`` looks for the value 1 in column 'a'
6201
6209
and the value 'z' in column 'b' and replaces these values
6202
6210
with whatever is specified in `value`. The `value` parameter
6203
6211
should not be ``None`` in this case. You can treat this as a
6204
6212
special case of passing two lists except that you are
6205
6213
specifying the column to search in.
6206
6214
- For a DataFrame nested dictionaries, e.g.,
6207
- ``{'a': {'b': np.nan}}``, are read as follows: look in column
6215
+ ``{{ 'a': {{ 'b': np.nan}} }}``, are read as follows: look in column
6208
6216
'a' for the value 'b' and replace it with NaN. The `value`
6209
6217
parameter should be ``None`` to use a nested dict in this
6210
6218
way. You can nest regular expressions as well. Note that
@@ -6237,7 +6245,7 @@ def bfill(
6237
6245
string. Alternatively, this could be a regular expression or a
6238
6246
list, dict, or array of regular expressions in which case
6239
6247
`to_replace` must be ``None``.
6240
- method : {'pad', 'ffill', 'bfill', `None`}
6248
+ method : {{ 'pad', 'ffill', 'bfill', `None`} }
6241
6249
The method to use when for replacement, when `to_replace` is a
6242
6250
scalar, list or tuple and `value` is ``None``.
6243
6251
@@ -6246,7 +6254,7 @@ def bfill(
6246
6254
6247
6255
Returns
6248
6256
-------
6249
- %( klass)s
6257
+ { klass}
6250
6258
Object after replacement.
6251
6259
6252
6260
Raises
@@ -6272,8 +6280,8 @@ def bfill(
6272
6280
6273
6281
See Also
6274
6282
--------
6275
- %( klass)s .fillna : Fill NA values.
6276
- %( klass)s .where : Replace values based on boolean condition.
6283
+ { klass} .fillna : Fill NA values.
6284
+ { klass} .where : Replace values based on boolean condition.
6277
6285
Series.str.replace : Simple string replacement.
6278
6286
6279
6287
Notes
@@ -6305,9 +6313,9 @@ def bfill(
6305
6313
4 4
6306
6314
dtype: int64
6307
6315
6308
- >>> df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
6316
+ >>> df = pd.DataFrame({{ 'A': [0, 1, 2, 3, 4],
6309
6317
... 'B': [5, 6, 7, 8, 9],
6310
- ... 'C': ['a', 'b', 'c', 'd', 'e']})
6318
+ ... 'C': ['a', 'b', 'c', 'd', 'e']}} )
6311
6319
>>> df.replace(0, 5)
6312
6320
A B C
6313
6321
0 5 5 a
@@ -6344,23 +6352,23 @@ def bfill(
6344
6352
6345
6353
**dict-like `to_replace`**
6346
6354
6347
- >>> df.replace({0: 10, 1: 100})
6355
+ >>> df.replace({{ 0: 10, 1: 100} })
6348
6356
A B C
6349
6357
0 10 5 a
6350
6358
1 100 6 b
6351
6359
2 2 7 c
6352
6360
3 3 8 d
6353
6361
4 4 9 e
6354
6362
6355
- >>> df.replace({'A': 0, 'B': 5}, 100)
6363
+ >>> df.replace({{ 'A': 0, 'B': 5} }, 100)
6356
6364
A B C
6357
6365
0 100 100 a
6358
6366
1 1 6 b
6359
6367
2 2 7 c
6360
6368
3 3 8 d
6361
6369
4 4 9 e
6362
6370
6363
- >>> df.replace({'A': {0: 100, 4: 400}})
6371
+ >>> df.replace({{ 'A': {{ 0: 100, 4: 400}} }})
6364
6372
A B C
6365
6373
0 100 5 a
6366
6374
1 1 6 b
@@ -6370,15 +6378,15 @@ def bfill(
6370
6378
6371
6379
**Regular expression `to_replace`**
6372
6380
6373
- >>> df = pd.DataFrame({'A': ['bat', 'foo', 'bait'],
6374
- ... 'B': ['abc', 'bar', 'xyz']})
6381
+ >>> df = pd.DataFrame({{ 'A': ['bat', 'foo', 'bait'],
6382
+ ... 'B': ['abc', 'bar', 'xyz']}} )
6375
6383
>>> df.replace(to_replace=r'^ba.$', value='new', regex=True)
6376
6384
A B
6377
6385
0 new abc
6378
6386
1 foo new
6379
6387
2 bait xyz
6380
6388
6381
- >>> df.replace({'A': r'^ba.$'}, {'A': 'new'}, regex=True)
6389
+ >>> df.replace({{ 'A': r'^ba.$'}} , {{ 'A': 'new'} }, regex=True)
6382
6390
A B
6383
6391
0 new abc
6384
6392
1 foo bar
@@ -6390,7 +6398,7 @@ def bfill(
6390
6398
1 foo new
6391
6399
2 bait xyz
6392
6400
6393
- >>> df.replace(regex={r'^ba.$': 'new', 'foo': 'xyz'})
6401
+ >>> df.replace(regex={{ r'^ba.$': 'new', 'foo': 'xyz'} })
6394
6402
A B
6395
6403
0 new abc
6396
6404
1 xyz new
@@ -6406,9 +6414,9 @@ def bfill(
6406
6414
the data types in the `to_replace` parameter must match the data
6407
6415
type of the value being replaced:
6408
6416
6409
- >>> df = pd.DataFrame({'A': [True, False, True],
6410
- ... 'B': [False, True, False]})
6411
- >>> df.replace({'a string': 'new value', True: False}) # raises
6417
+ >>> df = pd.DataFrame({{ 'A': [True, False, True],
6418
+ ... 'B': [False, True, False]}} )
6419
+ >>> df.replace({{ 'a string': 'new value', True: False} }) # raises
6412
6420
Traceback (most recent call last):
6413
6421
...
6414
6422
TypeError: Cannot compare types 'ndarray(dtype=bool)' and 'str'
@@ -6427,7 +6435,7 @@ def bfill(
6427
6435
``s.replace({'a': None})`` is equivalent to
6428
6436
``s.replace(to_replace={'a': None}, value=None, method=None)``:
6429
6437
6430
- >>> s.replace({'a': None})
6438
+ >>> s.replace({{ 'a': None} })
6431
6439
0 10
6432
6440
1 None
6433
6441
2 None
@@ -6450,17 +6458,6 @@ def bfill(
6450
6458
4 b
6451
6459
dtype: object
6452
6460
"""
6453
-
6454
- @Appender (_shared_docs ["replace" ] % _shared_doc_kwargs )
6455
- def replace (
6456
- self ,
6457
- to_replace = None ,
6458
- value = None ,
6459
- inplace = False ,
6460
- limit = None ,
6461
- regex = False ,
6462
- method = "pad" ,
6463
- ):
6464
6461
if not (
6465
6462
is_scalar (to_replace )
6466
6463
or isinstance (to_replace , pd .Series )
@@ -8246,17 +8243,29 @@ def ranker(data):
8246
8243
8247
8244
return ranker (data )
8248
8245
8249
- _shared_docs [
8250
- "align"
8251
- ] = """
8246
+ @doc (** _shared_doc_kwargs )
8247
+ def align (
8248
+ self ,
8249
+ other ,
8250
+ join = "outer" ,
8251
+ axis = None ,
8252
+ level = None ,
8253
+ copy = True ,
8254
+ fill_value = None ,
8255
+ method = None ,
8256
+ limit = None ,
8257
+ fill_axis = 0 ,
8258
+ broadcast_axis = None ,
8259
+ ):
8260
+ """
8252
8261
Align two objects on their axes with the specified join method.
8253
8262
8254
8263
Join method is specified for each axis Index.
8255
8264
8256
8265
Parameters
8257
8266
----------
8258
8267
other : DataFrame or Series
8259
- join : {'outer', 'inner', 'left', 'right'}, default 'outer'
8268
+ join : {{ 'outer', 'inner', 'left', 'right'} }, default 'outer'
8260
8269
axis : allowed axis of the other object, default None
8261
8270
Align on index (0), columns (1), or both (None).
8262
8271
level : int or level name, default None
@@ -8268,7 +8277,7 @@ def ranker(data):
8268
8277
fill_value : scalar, default np.NaN
8269
8278
Value to use for missing values. Defaults to NaN, but can be any
8270
8279
"compatible" value.
8271
- method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None
8280
+ method : {{ 'backfill', 'bfill', 'pad', 'ffill', None} }, default None
8272
8281
Method to use for filling holes in reindexed Series:
8273
8282
8274
8283
- pad / ffill: propagate last valid observation forward to next valid.
@@ -8281,32 +8290,18 @@ def ranker(data):
8281
8290
be partially filled. If method is not specified, this is the
8282
8291
maximum number of entries along the entire axis where NaNs will be
8283
8292
filled. Must be greater than 0 if not None.
8284
- fill_axis : %( axes_single_arg)s , default 0
8293
+ fill_axis : { axes_single_arg} , default 0
8285
8294
Filling axis, method and limit.
8286
- broadcast_axis : %( axes_single_arg)s , default None
8295
+ broadcast_axis : { axes_single_arg} , default None
8287
8296
Broadcast values along this axis, if aligning two objects of
8288
8297
different dimensions.
8289
8298
8290
8299
Returns
8291
8300
-------
8292
- (left, right) : (%( klass)s , type of other)
8301
+ (left, right) : ({ klass} , type of other)
8293
8302
Aligned objects.
8294
8303
"""
8295
8304
8296
- @Appender (_shared_docs ["align" ] % _shared_doc_kwargs )
8297
- def align (
8298
- self ,
8299
- other ,
8300
- join = "outer" ,
8301
- axis = None ,
8302
- level = None ,
8303
- copy = True ,
8304
- fill_value = None ,
8305
- method = None ,
8306
- limit = None ,
8307
- fill_axis = 0 ,
8308
- broadcast_axis = None ,
8309
- ):
8310
8305
method = missing .clean_fill_method (method )
8311
8306
8312
8307
if broadcast_axis == 1 and self .ndim != other .ndim :
@@ -8844,9 +8839,11 @@ def mask(
8844
8839
errors = errors ,
8845
8840
)
8846
8841
8847
- _shared_docs [
8848
- "shift"
8849
- ] = """
8842
+ @doc (klass = _shared_doc_kwargs ["klass" ])
8843
+ def shift (
8844
+ self : FrameOrSeries , periods = 1 , freq = None , axis = 0 , fill_value = None
8845
+ ) -> FrameOrSeries :
8846
+ """
8850
8847
Shift index by desired number of periods with an optional time `freq`.
8851
8848
8852
8849
When `freq` is not passed, shift the index without realigning the data.
@@ -8863,7 +8860,7 @@ def mask(
8863
8860
If `freq` is specified then the index values are shifted but the
8864
8861
data is not realigned. That is, use `freq` if you would like to
8865
8862
extend the index when shifting and preserve the original data.
8866
- axis : {0 or 'index', 1 or 'columns', None}, default None
8863
+ axis : {{ 0 or 'index', 1 or 'columns', None} }, default None
8867
8864
Shift direction.
8868
8865
fill_value : object, optional
8869
8866
The scalar value to use for newly introduced missing values.
@@ -8876,7 +8873,7 @@ def mask(
8876
8873
8877
8874
Returns
8878
8875
-------
8879
- %( klass)s
8876
+ { klass}
8880
8877
Copy of input object, shifted.
8881
8878
8882
8879
See Also
@@ -8889,9 +8886,9 @@ def mask(
8889
8886
8890
8887
Examples
8891
8888
--------
8892
- >>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45],
8889
+ >>> df = pd.DataFrame({{ 'Col1': [10, 20, 15, 30, 45],
8893
8890
... 'Col2': [13, 23, 18, 33, 48],
8894
- ... 'Col3': [17, 27, 22, 37, 52]})
8891
+ ... 'Col3': [17, 27, 22, 37, 52]}} )
8895
8892
8896
8893
>>> df.shift(periods=3)
8897
8894
Col1 Col2 Col3
@@ -8917,11 +8914,6 @@ def mask(
8917
8914
3 10 13 17
8918
8915
4 20 23 27
8919
8916
"""
8920
-
8921
- @Appender (_shared_docs ["shift" ] % _shared_doc_kwargs )
8922
- def shift (
8923
- self : FrameOrSeries , periods = 1 , freq = None , axis = 0 , fill_value = None
8924
- ) -> FrameOrSeries :
8925
8917
if periods == 0 :
8926
8918
return self .copy ()
8927
8919
0 commit comments