pyspark.pandas.Index.asof¶
-
Index.
asof
(label: Any) → Union[int, float, bool, str, bytes, decimal.Decimal, datetime.date, datetime.datetime, None][source]¶ Return the label from the index, or, if not present, the previous one.
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.
Note
This API is dependent on
Index.is_monotonic_increasing()
which can be expensive.- Parameters
- labelobject
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.
Examples
Index.asof returns the latest index label up to the passed label.
>>> idx = ps.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.
>>> 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.
>>> idx.asof('1999-01-02') nan