Return the last row(s) without any NaNs before `where`. The last row (for each element in `where`, if list) without any NaN is taken. In case of a :class:`~pandas.DataFrame`, the last row without NaN considering only the subset of columns (if not `None`)
(self, where, subset=None)
| 8074 | |
| 8075 | @final |
| 8076 | def asof(self, where, subset=None): |
| 8077 | """ |
| 8078 | Return the last row(s) without any NaNs before `where`. |
| 8079 | |
| 8080 | The last row (for each element in `where`, if list) without any |
| 8081 | NaN is taken. |
| 8082 | In case of a :class:`~pandas.DataFrame`, the last row without NaN |
| 8083 | considering only the subset of columns (if not `None`) |
| 8084 | |
| 8085 | If there is no good value, NaN is returned for a Series or |
| 8086 | a Series of NaN values for a DataFrame |
| 8087 | |
| 8088 | Parameters |
| 8089 | ---------- |
| 8090 | where : date or array-like of dates |
| 8091 | Date(s) before which the last row(s) are returned. |
| 8092 | subset : str or array-like of str, default `None` |
| 8093 | For DataFrame, if not `None`, only use these columns to |
| 8094 | check for NaNs. |
| 8095 | |
| 8096 | Returns |
| 8097 | ------- |
| 8098 | scalar, Series, or DataFrame |
| 8099 | |
| 8100 | The return can be: |
| 8101 | |
| 8102 | * scalar : when `self` is a Series and `where` is a scalar |
| 8103 | * Series: when `self` is a Series and `where` is an array-like, |
| 8104 | or when `self` is a DataFrame and `where` is a scalar |
| 8105 | * DataFrame : when `self` is a DataFrame and `where` is an |
| 8106 | array-like |
| 8107 | |
| 8108 | See Also |
| 8109 | -------- |
| 8110 | merge_asof : Perform an asof merge. Similar to left join. |
| 8111 | |
| 8112 | Notes |
| 8113 | ----- |
| 8114 | Dates are assumed to be sorted. Raises if this is not the case. |
| 8115 | |
| 8116 | Examples |
| 8117 | -------- |
| 8118 | A Series and a scalar `where`. |
| 8119 | |
| 8120 | >>> s = pd.Series([1, 2, np.nan, 4], index=[10, 20, 30, 40]) |
| 8121 | >>> s |
| 8122 | 10 1.0 |
| 8123 | 20 2.0 |
| 8124 | 30 NaN |
| 8125 | 40 4.0 |
| 8126 | dtype: float64 |
| 8127 | |
| 8128 | >>> s.asof(20) |
| 8129 | np.float64(2.0) |
| 8130 | |
| 8131 | For a sequence `where`, a Series is returned. The first value is |
| 8132 | NaN, because the first element of `where` is before the first |
| 8133 | index value. |
no test coverage detected