pandas 1.4.2

ParametersReturnsBackRef
asof(self, label)

Assuming that the index is sorted, return the passed index label if it is in the index, or return the previous index label if the passed one is not in the index.

Parameters

label : object

The label up to which the method returns the latest index label.

Returns

object

The passed label if it is in the index. The previous label if the passed label is not in the sorted index or NaN if there is no such label.

Return the label from the index, or, if not present, the previous one.

See Also

Index.get_loc

An :None:None:`asof` is a thin wrapper around :None:None:`get_loc` with method='pad'.

Series.asof

Return the latest value in a Series up to the passed index.

merge_asof

Perform an asof merge (similar to left join but it matches on nearest key rather than equal key).

Examples

Index.asof returns the latest index label up to the passed label.

This example is valid syntax, but we were not able to check execution
>>> idx = pd.Index(['2013-12-31', '2014-01-02', '2014-01-03'])
... idx.asof('2014-01-01') '2013-12-31'

If the label is in the index, the method returns the passed label.

This example is valid syntax, but we were not able to check execution
>>> idx.asof('2014-01-02')
'2014-01-02'

If all of the labels in the index are later than the passed label, NaN is returned.

This example is valid syntax, but we were not able to check execution
>>> idx.asof('1999-01-02')
nan

If the index is not sorted, an error is raised.

This example is valid syntax, but we were not able to check execution
>>> idx_not_sorted = pd.Index(['2013-12-31', '2015-01-02',
...  '2014-01-03'])
... idx_not_sorted.asof('2013-12-31') Traceback (most recent call last): ValueError: index must be monotonic increasing or decreasing
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.indexes.base.Index.asof pandas.core.indexes.base.Index.asof_locs

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/indexes/base.py#5285
type: <class 'function'>
Commit: