w3resource

Pandas Series: asof() function

Get the last row(s) without any NaNs in Pandas series

The asof() function is used to 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 DataFrame, the last row without NaN considering only the subset of columns (if not None)

New in version 0.19.0: For DataFrame

If there is no good value, NaN is returned for a Series or a Series of NaN values for a DataFrame

Syntax:

Series.asof(self, where, subset=None)
Pandas Series asof image

Parameters:

Name Description Type/Default Value Required / Optional
where   Date(s) before which the last row(s) are returned. date or array-like of dates Required
subset For DataFrame, if not None, only use these columns to check for NaNs. str or array-like of str
Default Value: None
Required

Returns: scalar, Series, or DataFrame
The return can be:

  • scalar : when self is a Series and where is a scalar
  • Series: when self is a Series and where is an array-like, or when self is a DataFrame and where is a scalar
  • DataFrame : when self is a DataFrame and where is an array-like

Return scalar, Series, or DataFrame.

Notes: Dates are assumed to be sorted. Raises if this is not the case.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts