Examples
A Series and a scalar:
import numpy as np
import pandas as pd
s = pd.Series([2, 3, np.nan, 5], index=[20, 30, 40, 50])
s
s.asof(30)
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([6, 30])
Missing values are not considered. The following is 3.0, not NaN, even though
NaN is at the index location for 40.
s.asof(40)
Take all columns into consideration:
df = pd.DataFrame({'p': [20, 30, 40, 50, 60],
'q': [None, None, None, None, 600]},
index=pd.DatetimeIndex(['2019-02-27 09:01:00',
'2019-02-27 09:02:00',
'2019-02-27 09:03:00',
'2019-02-27 09:04:00',
'2019-02-27 09:05:00']))
df.asof(pd.DatetimeIndex(['2019-02-27 09:03:30',
'2019-02-27 09:04:30']))
Take a single column into consideration:
df.asof(pd.DatetimeIndex(['2019-02-27 09:03:30',
'2019-02-27 09:04:30']),
subset=['p'])