@@ -6497,40 +6497,98 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
6497
6497
6498
6498
def asof (self , where , subset = None ):
6499
6499
"""
6500
- The last row without any NaN is taken (or the last row without
6501
- NaN considering only the subset of columns in the case of a DataFrame)
6500
+ Return the last row(s) without any `NaN`s before `where`.
6501
+
6502
+ The last row (for each element in `where`, if list) without any
6503
+ `NaN` is taken.
6504
+ In case of a :class:`~pandas.DataFrame`, the last row without `NaN`
6505
+ considering only the subset of columns (if not `None`)
6502
6506
6503
6507
.. versionadded:: 0.19.0 For DataFrame
6504
6508
6505
- If there is no good value, NaN is returned for a Series
6509
+ If there is no good value, ` NaN` is returned for a Series or
6506
6510
a Series of NaN values for a DataFrame
6507
6511
6508
6512
Parameters
6509
6513
----------
6510
- where : date or array of dates
6511
- subset : string or list of strings, default None
6512
- if not None use these columns for NaN propagation
6514
+ where : date or array-like of dates
6515
+ Date(s) before which the last row(s) are returned.
6516
+ subset : str or array-like of str, default `None`
6517
+ For DataFrame, if not `None`, only use these columns to
6518
+ check for `NaN`s.
6513
6519
6514
6520
Notes
6515
6521
-----
6516
- Dates are assumed to be sorted
6517
- Raises if this is not the case
6522
+ Dates are assumed to be sorted. Raises if this is not the case.
6518
6523
6519
6524
Returns
6520
6525
-------
6521
- where is scalar
6522
-
6523
- - value or NaN if input is Series
6524
- - Series if input is DataFrame
6526
+ scalar, Series, or DataFrame
6525
6527
6526
- where is Index: same shape object as input
6528
+ * scalar : when `self` is a Series and `where` is a scalar
6529
+ * Series: when `self` is a Series and `where` is an array-like,
6530
+ or when `self` is a DataFrame and `where` is a scalar
6531
+ * DataFrame : when `self` is a DataFrame and `where` is an
6532
+ array-like
6527
6533
6528
6534
See Also
6529
6535
--------
6530
- merge_asof
6536
+ merge_asof : Perform an asof merge. Similar to left join.
6531
6537
6532
- """
6538
+ Examples
6539
+ --------
6540
+ A Series and a scalar `where`.
6541
+
6542
+ >>> s = pd.Series([1, 2, np.nan, 4], index=[10, 20, 30, 40])
6543
+ >>> s
6544
+ 10 1.0
6545
+ 20 2.0
6546
+ 30 NaN
6547
+ 40 4.0
6548
+ dtype: float64
6549
+
6550
+ >>> s.asof(20)
6551
+ 2.0
6533
6552
6553
+ For a sequence `where`, a Series is returned. The first value is
6554
+ ``NaN``, because the first element of `where` is before the first
6555
+ index value.
6556
+
6557
+ >>> s.asof([5, 20])
6558
+ 5 NaN
6559
+ 20 2.0
6560
+ dtype: float64
6561
+
6562
+ Missing values are not considered. The following is ``2.0``, not
6563
+ ``NaN``, even though ``NaN`` is at the index location for ``30``.
6564
+
6565
+ >>> s.asof(30)
6566
+ 2.0
6567
+
6568
+ Take all columns into consideration
6569
+
6570
+ >>> df = pd.DataFrame({'a': [10, 20, 30, 40, 50],
6571
+ ... 'b': [None, None, None, None, 500]},
6572
+ ... index=pd.DatetimeIndex(['2018-02-27 09:01:00',
6573
+ ... '2018-02-27 09:02:00',
6574
+ ... '2018-02-27 09:03:00',
6575
+ ... '2018-02-27 09:04:00',
6576
+ ... '2018-02-27 09:05:00']))
6577
+ >>> df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30',
6578
+ ... '2018-02-27 09:04:30']))
6579
+ a b
6580
+ 2018-02-27 09:03:30 NaN NaN
6581
+ 2018-02-27 09:04:30 NaN NaN
6582
+
6583
+ Take a single column into consideration
6584
+
6585
+ >>> df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30',
6586
+ ... '2018-02-27 09:04:30']),
6587
+ ... subset=['a'])
6588
+ a b
6589
+ 2018-02-27 09:03:30 30.0 NaN
6590
+ 2018-02-27 09:04:30 40.0 NaN
6591
+ """
6534
6592
if isinstance (where , compat .string_types ):
6535
6593
from pandas import to_datetime
6536
6594
where = to_datetime (where )
0 commit comments