pandas.Index.asof#
- final Index.asof(label)[源代码]#
返回索引中的标签,如果不存在,则返回前一个标签。
假定索引已排序,如果传递的索引标签在索引中,则返回该索引标签;如果传递的索引标签不在索引中,则返回前一个索引标签。
- 参数
- label对象
该方法返回最新索引标签的标签。
- 退货
- 对象
传递的标签(如果它在索引中)。如果传递的标签不在排序索引中,则返回上一个标签 NaN 如果没有这样的标签。
参见
Series.asof
返回序列中最新的值,直到传递的索引。
merge_asof
执行asof合并(类似于左联接,但它匹配最近的键而不是相等的键)。
Index.get_loc
一个 asof 是一层薄薄的包装纸 get_loc With method=‘Pad’。
示例
Index.asof 返回最新的索引标签,直到传递的标签。
>>> idx = pd.Index(['2013-12-31', '2014-01-02', '2014-01-03']) >>> idx.asof('2014-01-01') '2013-12-31'
如果标签在索引中,则该方法返回传递的标签。
>>> idx.asof('2014-01-02') '2014-01-02'
如果索引中的所有标签都晚于传递的标签,则返回NaN。
>>> idx.asof('1999-01-02') nan
如果索引未排序,则会引发错误。
>>> 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