pandas 1.4.2

NotesParametersReturns
asof(self, where, subset=None)

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

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

Notes

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

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:None:`None`, only use these columns to check for NaNs.

Returns

scalar, Series, or DataFrame

The return can be:

Return the last row(s) without any NaNs before where .

See Also

merge_asof

Perform an asof merge. Similar to left join.

Examples

A Series and a scalar where .

This example is valid syntax, but we were not able to check execution
>>> 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
This example is valid syntax, but we were not able to check execution
>>> 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.

This example is valid syntax, but we were not able to check execution
>>> 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 .

This example is valid syntax, but we were not able to check execution
>>> s.asof(30)
2.0

Take all columns into consideration

This example is valid syntax, but we were not able to check execution
>>> 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

This example is valid syntax, but we were not able to check execution
>>> 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
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/generic.py#7057
type: <class 'function'>
Commit: