def asof(self, where, subset=None):
if isinstance(where, str):<EOL><INDENT>from pandas import to_datetime<EOL>where = to_datetime(where)<EOL><DEDENT>if not self.index.is_monotonic:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>is_series = isinstance(self, ABCSeries)<EOL>if is_series:<EOL><INDENT>if subset is not None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>elif self.ndim > <NUM_LIT:2>:<EOL><INDENT>raise NotImplementedError("<STR_LIT>"<EOL>"<STR_LIT>".format(type=type(self)))<EOL><DEDENT>else:<EOL><INDENT>if subset is None:<EOL><INDENT>subset = self.columns<EOL><DEDENT>if not is_list_like(subset):<EOL><INDENT>subset = [subset]<EOL><DEDENT><DEDENT>is_list = is_list_like(where)<EOL>if not is_list:<EOL><INDENT>start = self.index[<NUM_LIT:0>]<EOL>if isinstance(self.index, PeriodIndex):<EOL><INDENT>where = Period(where, freq=self.index.freq).ordinal<EOL>start = start.ordinal<EOL><DEDENT>if where < start:<EOL><INDENT>if not is_series:<EOL><INDENT>from pandas import Series<EOL>return Series(index=self.columns, name=where)<EOL><DEDENT>return np.nan<EOL><DEDENT>if is_series:<EOL><INDENT>loc = self.index.searchsorted(where, side='<STR_LIT:right>')<EOL>if loc > <NUM_LIT:0>:<EOL><INDENT>loc -= <NUM_LIT:1><EOL><DEDENT>values = self._values<EOL>while loc > <NUM_LIT:0> and isna(values[loc]):<EOL><INDENT>loc -= <NUM_LIT:1><EOL><DEDENT>return values[loc]<EOL><DEDENT><DEDENT>if not isinstance(where, Index):<EOL><INDENT>where = Index(where) if is_list else Index([where])<EOL><DEDENT>nulls = self.isna() if is_series else self[subset].isna().any(<NUM_LIT:1>)<EOL>if nulls.all():<EOL><INDENT>if is_series:<EOL><INDENT>return self._constructor(np.nan, index=where, name=self.name)<EOL><DEDENT>elif is_list:<EOL><INDENT>from pandas import DataFrame<EOL>return DataFrame(np.nan, index=where, columns=self.columns)<EOL><DEDENT>else:<EOL><INDENT>from pandas import Series<EOL>return Series(np.nan, index=self.columns, name=where[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>locs = self.index.asof_locs(where, ~(nulls.values))<EOL>missing = locs == -<NUM_LIT:1><EOL>data = self.take(locs, is_copy=False)<EOL>data.index = where<EOL>data.loc[missing] = np.nan<EOL>return data if is_list else data.iloc[-<NUM_LIT:1>]<EOL>
Return the last row(s) without any NaNs before `where`.

The last row (for each element in `where`, if list) without any
NaN is taken.
In case of a :class:`~pandas.DataFrame`, the last row without NaN
considering only the subset of columns (if not `None`)

.. versionadded:: 0.19.0 For DataFrame

If there is no good value, NaN is returned for a Series or
a Series of NaN values for a DataFrame

Parameters
----------
where : date or array-like of dates
    Date(s) before which the last row(s) are returned.
subset : str or array-like of str, default `None`
    For DataFrame, if not `None`, only use these columns to
    check for NaNs.

Returns
-------
scalar, Series, or DataFrame

    The return can be:

    * scalar : when `self` is a Series and `where` is a scalar
    * Series: when `self` is a Series and `where` is an array-like,
      or when `self` is a DataFrame and `where` is a scalar
    * DataFrame : when `self` is a DataFrame and `where` is an
      array-like

    Return scalar, Series, or DataFrame.

See Also
--------
merge_asof : Perform an asof merge. Similar to left join.

Notes
-----
Dates are assumed to be sorted. Raises if this is not the case.

Examples
--------
A Series and a scalar `where`.

>>> s = pd.Series([1, 2, np.nan, 4], index=[10, 20, 30, 40])
>>> s
10    1.0
20    2.0
30    NaN
40    4.0
dtype: float64

>>> s.asof(20)
2.0

For a sequence `where`, a Series is returned. The first value is
NaN, because the first element of `where` is before the first
index value.

>>> s.asof([5, 20])
5     NaN
20    2.0
dtype: float64

Missing values are not considered. The following is ``2.0``, not
NaN, even though NaN is at the index location for ``30``.

>>> s.asof(30)
2.0

Take all columns into consideration

>>> df = pd.DataFrame({'a': [10, 20, 30, 40, 50],
...                    'b': [None, None, None, None, 500]},
...                   index=pd.DatetimeIndex(['2018-02-27 09:01:00',
...                                           '2018-02-27 09:02:00',
...                                           '2018-02-27 09:03:00',
...                                           '2018-02-27 09:04:00',
...                                           '2018-02-27 09:05:00']))
>>> df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30',
...                           '2018-02-27 09:04:30']))
                      a   b
2018-02-27 09:03:30 NaN NaN
2018-02-27 09:04:30 NaN NaN

Take a single column into consideration

>>> df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30',
...                           '2018-02-27 09:04:30']),
...         subset=['a'])
                         a   b
2018-02-27 09:03:30   30.0 NaN
2018-02-27 09:04:30   40.0 NaN