MCPcopy
hub / github.com/pandas-dev/pandas / asof

Method asof

pandas/core/generic.py:8076–8252  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 5

time_asofMethod · 0.45
time_asof_nanMethod · 0.45
time_asof_singleMethod · 0.45
time_asof_nan_singleMethod · 0.45

Calls 10

isnaMethod · 0.95
_constructorMethod · 0.95
takeMethod · 0.95
isnaFunction · 0.90
IndexClass · 0.85
_constructor_slicedMethod · 0.45
searchsortedMethod · 0.45
anyMethod · 0.45
allMethod · 0.45
asof_locsMethod · 0.45

Tested by

no test coverage detected